OOP LINKED LIST EXAMPLE

#include<iostream>
#include<conio.h>
using namespace std;
struct nodetype
{
int info;
nodetype *link;
};
main()
{
int num;
nodetype *first,*last,*current,*t,*j,*q,*d;
first=NULL;
last=NULL;
for(int k=0;k<4;k++)
{
cin>>num;
current= new nodetype;
current->link=NULL;
current->info=num;
if(first==NULL){
first=current;
last=current;
}

else{
last->link=current;
last=current;
}
}
j=first;
cout<<"numer are"<<endl;
while(j!=NULL){
cout<<j->info<<endl;
j=j->link;}
q=first;
t=first->link;
delete q;
 j=t;
cout<<"numberr are"<<endl;
while(j!=NULL)
{cout<<j->info<<endl;
j=j->link;
}
d=last;
t->link->link=NULL;
delete d;
j=t;
cout<<"numberr are"<<endl;
while(j!=NULL){
cout<<j->info<<endl;
j=j->link;
}
getch();
}

Comments

Popular posts from this blog