diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 00000000..e322d00b Binary files /dev/null and b/.DS_Store differ diff --git a/linklist/traversal.cc b/linklist/traversal.cc new file mode 100644 index 00000000..ca2dbefb --- /dev/null +++ b/linklist/traversal.cc @@ -0,0 +1,52 @@ +#include +using namespace std; + +class Node{ + public: + int data; + Node* next; + Node(int d){ + data = d; + next = NULL; + } +}; + +Node* insertAtEnd(Node* head, int x, Node* &tail){ + if (head == NULL){ + head = new Node(x); + tail = head; + return head; + } + + tail->next = new Node(x); + tail = tail->next; + return head; +} + +Node* createLL(){ + int x; + Node* head = NULL; + Node* tail = NULL; + + while(true){ + cin >> x; + if (x == -1) break; + head = insertAtEnd(head, x, tail); + } + return head; +} + +void printLL(Node* head){ + Node* cur = head; + while(cur != NULL){ + cout << cur->data << "-->"; + cur = cur->next; + } + cout << endl; +} +int main(){ + //enter -1 for last number + Node* head=createLL(); + //To traverse use printLL + printLL(head); +} \ No newline at end of file diff --git a/searching/.DS_Store b/searching/.DS_Store new file mode 100644 index 00000000..5008ddfc Binary files /dev/null and b/searching/.DS_Store differ