Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added link list traversal code #74

Merged
merged 1 commit into from
Oct 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
52 changes: 52 additions & 0 deletions linklist/traversal.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include <iostream>
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);
}
Binary file added searching/.DS_Store
Binary file not shown.