Skip to content

Instantly share code, notes, and snippets.

@yasith
Created August 13, 2011 06:41
Show Gist options
  • Save yasith/1143551 to your computer and use it in GitHub Desktop.
Save yasith/1143551 to your computer and use it in GitHub Desktop.
Simple Linked List
#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