//Creation of linklist by using the concept of Parallel Array
#include<iostream.h>
#include<conio.h>
int main()
{
clrscr();
int info[10],link[10],item,p,i;
for(i=1;i<10;i++)
{link[i]=i+1;}
link[i]=0;
int start=0,free=1,node=0;
char ch;
do
{
if(start==0)
{
start=free;
cout<<"enter the item to insert ";
cin>>item;
info[start]=item;
free=link[free];
link[start]=0;
node++;
}
else
{
p=start;
while(link[p]!=0)
{p=link[p];}
link[p]=free;
p=link[p];
cout<<"enter the no to be insert ";
cin>>item;
info[p]=item;
free=link[free];
link[p]=0;
node++;
}
cout<<"wants to continue y or n: ";
cin>>ch;
}while(ch=='y');
cout<<"created linklist are ";
for(i=1;i<=node;i++)
cout<<info[i]<<" ";
return 0;
getch();
}
#include<iostream.h>
#include<conio.h>
int main()
{
clrscr();
int info[10],link[10],item,p,i;
for(i=1;i<10;i++)
{link[i]=i+1;}
link[i]=0;
int start=0,free=1,node=0;
char ch;
do
{
if(start==0)
{
start=free;
cout<<"enter the item to insert ";
cin>>item;
info[start]=item;
free=link[free];
link[start]=0;
node++;
}
else
{
p=start;
while(link[p]!=0)
{p=link[p];}
link[p]=free;
p=link[p];
cout<<"enter the no to be insert ";
cin>>item;
info[p]=item;
free=link[free];
link[p]=0;
node++;
}
cout<<"wants to continue y or n: ";
cin>>ch;
}while(ch=='y');
cout<<"created linklist are ";
for(i=1;i<=node;i++)
cout<<info[i]<<" ";
return 0;
getch();
}
it really works
ReplyDeleteBilkul Sahi hai
ReplyDelete