Last active
January 21, 2016 07:17
-
-
Save irvifa/ba150f03627486a84069 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Node { | |
public: | |
int data; | |
Node *next; | |
Node(int d){ | |
data=d; | |
next=NULL; | |
} | |
}; | |
class LinkedList { | |
public: | |
Node* insert(Node *head,int data) { | |
Node* curr = head; | |
Node* newNode = new Node(data); | |
while(curr && curr->next!=NULL) curr=curr->next; | |
(curr==NULL)? head=newNode:curr->next= newNode; | |
return head; | |
} | |
void display(Node *head) { | |
Node *start=head; | |
while (start) { | |
cout<<start->data<<" "; | |
start=start->next; | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment