Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream.h>
- #include<conio.h>
- #include<process.h>
- class node
- {
- public:
- int info;
- node *next;
- }*start,*newptr,*save,*ptr,*rear;
- node *create_new_node(int n)
- {
- ptr=new node;
- ptr->info=n;
- ptr->next=NULL;
- return ptr;
- }
- void Insert(node *np)
- {
- if(start==NULL)
- start=rear=np;
- else
- {
- rear->next=np;
- rear=np;
- }
- }
- void delnode()
- {
- if(start==NULL)
- cout<<"UNDERFLOW!!!\n";
- else
- {
- ptr=start;
- start=start->next;
- delete ptr;
- }
- }
- void display(node *np)
- {
- while (np!=NULL)
- {
- cout<<np->info<<" -> ";
- np=np->next;
- }
- cout<<"!!!\n";
- }
- void main()
- {
- start=rear=NULL;
- int inf;
- char ch='y';
- while (ch=='y'||ch=='Y')
- {
- clrscr();
- cout<<"\nEnter INFOrmation for the new node...";
- cin>>inf;
- newptr=create_new_node(inf);
- if (newptr==NULL)
- {
- cout<<"\nCannot create new node!!!Aborting!!\n";
- getch();
- exit(1);
- }
- Insert(newptr);
- cout<<"\nPress Y to enter more nodes,N to exit...\n";
- cin>>ch;
- }
- clrscr();
- do
- {
- cout<<"\nThe list now is: \n";
- display(start);
- getch();
- cout<<"Want to delete first node?(y/n)...";
- cin>>ch;
- if (ch=='y'||ch=='Y')
- delnode();
- }
- while(ch=='y'||ch=='Y');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement