Skip to content

Instantly share code, notes, and snippets.

@irvifa
Last active January 21, 2016 07:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save irvifa/ba150f03627486a84069 to your computer and use it in GitHub Desktop.
Save irvifa/ba150f03627486a84069 to your computer and use it in GitHub Desktop.
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