CURSOR IMPLEMENTATION OF LIST ADT
AIM:
To write a program to implement Cursor of List ADT.


ALGORITHM:
1.CREATION
STEP 1:  allocate the memory to store the data for the data field which is started 
from the first node
STEP 2: Get the free node from the link of the first node.
STEP 3: Assign the link of the new node to link of the first node
STEP 4: Assign the link of the new node to zero.
STEP 5: The next free node is found from the link of the first node.


2.DELETION
STEP 1: To remove a node from the list memory has to be deallocated.
STEP 2: Assign the link of the removed node with the link of the first node.
STEP 3: Assign the link of the first node with the index of the node to be
removed.  

PROGRAM:
#include<iostream.h>
#include<conio.h> #include<stdlib.h>
#define MAX 20
class LIST
{
private:
int List[MAX];
public:
int create();
void display(int); void reverse(int);
int Search(int); void delet(int);
};
int LIST::create()
{
int n,i;
clrscr();
cout<<"\n How many elements you want in the list:";
cin>>n;
if(n>MAX)
cout<<"\n Error:Number of elements exceed the limit";
for(i=0;i<n;i++)
{
cout<<"\n Enter the element Number"<<i+1<<":";
cin>>List[i];
}
cout<<"\n The List is successfully created \n";
getch();
return(n);
}
void LIST::display(int n)
{
int i;
clrscr();
cout<<"\n The List is...\n";
for(i=0;i<n;i++)
cout<<"\n"<<List[i];
cout<<"\n Press any key to continue...\n";
getch();
}
void LIST::reverse(int n)
{
int i;
clrscr();
cout<<"\n The Reversed List is...\n";
for(i=n-1;i>=0;i--)
cout<<"\n"<<List[i];
cout<<"\n Press any key to continue...\n";
getch();
}
int LIST::Search(int n)
{
int i,key;
clrscr();
cout<<"\n Enter the number you want to Search?";
cin>>key;
for(i=0;i<n;i++)
{
if(List[i]==key)
{
cout<<"\n The given number is at position:"<<i<<"\n";
getch();
return i;
}
}
cout<<"\n The given number is not in the list \n";
getch();
return -1;
}
void LIST::delet(int n)
{
int i;
i=Search(n);
List[i]=-1;
cout<<"\n The element is now deleted";
cout<<"\n We put -1 to indicate empty location";
getch();
}
void main()
{
LIST obj;
int choice,len,position;
char ans;
do
{
clrscr();
cout<<"\n\t Program to perform operation on ordered list:";
cout<<"\n 1.Create";
cout<<"\n 2.Display";
cout<<"\n 3.Search for a Number";
cout<<"\n 4.Reverse";
cout<<"\n 5.Delete";
cout<<"\n 6.Quit";
cout<<"\n Enter your choice(1-6)";
cin>>choice;
switch(choice)
{
case 1:
len=obj.create();
break;
case 2:
obj.display(len);
break;
case 3:
position=obj.Search(len);
break;
case 4:
obj.reverse(len);
break;
case 5:obj.delet(len);
break;
case 6:
cout<<"\n Do you want to Exit(y/n)?";
ans=getch();
if(ans=='y')
exit(0);
else
break;
default: clrscr();
cout<<"\n Invalid Choice,Try Again";
getch();
}
}
while(choice!=6);
}
OUTPUT:
Program to perform operation on ordered list:
1.Create
2.Display
3.Search for a Number
4.Reverse
5.Delete
6.Quit

Enter your choice(1-6)1
How many elements you want in the list:5
Enter the element Number 1: 10
Enter the element Number 2:20
Enter the element Number 3:30
Enter the element Number 4:40

Enter the element Number 5:50
The List is successfully created

Enter your choice(1-6)2
The List is...
10
20 30 40 50
Press any key to continue... Enter your choice(1-6)3
Enter the number you want to Search?40
The given number is at position:3

Enter your choice(1-6) 4
The Reversed List is...
50
40 30 20 10
Press any key to continue….

Enter your choice(1-6) 5
Enter the number you want to Search?20
The given number is at position:1
The element is now deleted
We put -1 to indicate empty location

Enter your choice(1-6)6 Do you want to Exit(y/n)? n