Choose Category
# include <iostream.h> # include <conio.h> # include <process.h> struct node { int info; node *next; } *start, *newptr, *save, *ptr; node *create_new_node( int); void insert_beg(node*); void display(node*); void main() {clrscr(); start = NULL; int inf; char ch ='y'; while(ch =='y' || ch=='Y') { cout <<"\n Enter info for the new node..."; cin >> inf; cout <<"\n Creating new node!! Press enter to continue......."; getch(); newptr = create_new_node( inf); cout <<"\nNow inserting this node in the beginning of list...\n"; cout <<"Press enter to continue..\n"; getch(); insert_beg( newptr); cout <<"\nNow the list is : \n"; display(start); cout <<"\n Press Y to enter more nodes, n to exit...\n"; cin >>ch; } getch(); } node * create_new_node( int n) {ptr = new node; ptr->info=n; ptr->next= NULL; return ptr; } void insert_beg(node* np) { if (start == NULL) start = np; else {save = start; start = np; np->next = save; } } void display(node* np) { while(np!=NULL) {cout <<np->info<<"->"; np = np->next; } cout <<"!!!\n"; }