Created
August 13, 2011 06:41
-
-
Save yasith/1143551 to your computer and use it in GitHub Desktop.
Simple Linked List
This file contains 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
#include <string> | |
#include <iostream> | |
using namespace std; | |
class Node{ | |
public: | |
string s; | |
int id; | |
Node *next; | |
void add(string str){ | |
Node *n = new Node; | |
n->next = next; | |
n->s = str; | |
next = n; | |
} | |
} llist; | |
void print(Node *n){ | |
if(n == NULL){ | |
cout << "End of List" << endl; | |
return; | |
} | |
cout << n->s << endl; | |
print(n->next); | |
return; | |
} | |
int main(){ | |
llist.next = NULL; | |
while(true){ | |
string s; | |
cin >> s; | |
if(s == "exit"){ | |
cout << "Exiting" << endl; | |
break; | |
} | |
llist.add(s); | |
} | |
print(llist.next); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment