Created
February 11, 2012 13:40
-
-
Save nmepntgrm/1799480 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
| #include <iostream> | |
| #include <string> | |
| using namespace std; | |
| int flag = 0; | |
| struct Node | |
| { | |
| string info; | |
| struct Node *link; | |
| }*start; | |
| void createList(string data) | |
| { | |
| struct Node *q,*tmp; | |
| tmp = new Node; | |
| tmp->info = data; | |
| if(start == NULL) | |
| { | |
| start = tmp; | |
| } | |
| else | |
| { | |
| q = start; | |
| while(q->link != NULL) | |
| q = q->link; | |
| q->link = tmp; | |
| } | |
| } | |
| void display() | |
| { | |
| struct Node *q; | |
| if(start == NULL) | |
| { | |
| cout << "\n\nList is empty"; | |
| return; | |
| } | |
| q = start; | |
| cout << "\n\nList is : "; | |
| while(q != NULL) | |
| { | |
| cout << q->info << "->"; | |
| q = q->link; | |
| } | |
| cout << "\n"; | |
| } | |
| void addAtAfter(string tempData) | |
| { | |
| createList(tempData); | |
| return; | |
| } | |
| void addAtBeginning(string tempData) | |
| { | |
| struct Node *q,*tmp; | |
| tmp = new Node; | |
| tmp->info = tempData; | |
| if(start == NULL){ | |
| tmp->link = NULL; | |
| } | |
| else{ | |
| tmp->link = start; | |
| start = tmp; | |
| } | |
| } | |
| int main() | |
| { | |
| //kaw na bahala sa menu, function calls nlng | |
| createList("hello"); | |
| display(); | |
| addAtAfter("hello2"); | |
| display(); | |
| addAtBeginning("hello3"); | |
| display(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment