Array Implementation of List ADT
Program
#include<iostream>
using namespace std;
void CreateList();
void DeleteFromList();
void SearchInList();
void InsertIntoList();
void DisplayList();
int
list[20],total_elements,delete_position,search_element,insert_number
,position_to_insert,i;
int main()
{
int choose_option;
char yes_no='y';
do
{
cout<<"ttMain Menun";
cout<<"n1.Create Listn2.Delete From Listn3.Search In
Listn4.Insert Into Listn5.Display Listn";
cout<<"nEnter Your Choicen";
cin>>choose_option;
switch(choose_option)
{
case 1: CreateList();
break;
case 2: DeleteFromList();
break;
case 3: SearchInList();
break;
case 4: InsertIntoList();
break;
case 5: DisplayList();
break;
default:cout<<"The given no. is not between 1-5n";
}
cout<<"Do U want to continue (Y/N):";
cin>>yes_no;
}
while(yes_no=='y'||yes_no=='Y');
return 0;
}
void CreateList()
{
cout<<"nEnter the no. of elementsn";
cin>>total_elements;
cout<<"Enter the no:n";
for(i=0;i<total_elements;i++)
{
cin>>list[i];
}
}
void DeleteFromList()
{
cout<<"Enter the position you want to deleten";
cin>>delete_position;
for(i=delete_position;i<total_elements;i++)
{
list[i-1]=list[i];
}
total_elements--;
}
void SearchInList()
{
cout<<"Enter the no. to searchn";
cin>>search_element;
for(i=0;i<total_elements;i++)
{
if(list[i]==search_element)
break;
}
if(i==total_elements)
cout<<"Number Not Found"<<endl;
else
cout<<"The No. is at"<<i+1<<"positionn";
}
void InsertIntoList()
{
cout<<"Enter the no. to insertn";
cin>>insert_number;
cout<<"Enter the positionn";
cin>>position_to_insert;
for(i=total_elements-1;i>=position_to_insert-1;i--)
{
list[i+1]=list[i];
}
list[position_to_insert-1]=insert_number;
total_elements++;
}
void DisplayList()
{
cout<<"n";
for(i=0;i<total_elements;i++)
{
cout<<"t"<<list[i];
}
}

array implementation

  • 1.
    Array Implementation ofList ADT Program #include<iostream> using namespace std; void CreateList(); void DeleteFromList(); void SearchInList(); void InsertIntoList(); void DisplayList(); int list[20],total_elements,delete_position,search_element,insert_number ,position_to_insert,i; int main() { int choose_option; char yes_no='y'; do { cout<<"ttMain Menun"; cout<<"n1.Create Listn2.Delete From Listn3.Search In Listn4.Insert Into Listn5.Display Listn"; cout<<"nEnter Your Choicen"; cin>>choose_option; switch(choose_option) { case 1: CreateList(); break; case 2: DeleteFromList(); break; case 3: SearchInList(); break; case 4: InsertIntoList(); break; case 5: DisplayList(); break; default:cout<<"The given no. is not between 1-5n"; } cout<<"Do U want to continue (Y/N):"; cin>>yes_no; } while(yes_no=='y'||yes_no=='Y'); return 0; } void CreateList() { cout<<"nEnter the no. of elementsn";
  • 2.
    cin>>total_elements; cout<<"Enter the no:n"; for(i=0;i<total_elements;i++) { cin>>list[i]; } } voidDeleteFromList() { cout<<"Enter the position you want to deleten"; cin>>delete_position; for(i=delete_position;i<total_elements;i++) { list[i-1]=list[i]; } total_elements--; } void SearchInList() { cout<<"Enter the no. to searchn"; cin>>search_element; for(i=0;i<total_elements;i++) { if(list[i]==search_element) break; } if(i==total_elements) cout<<"Number Not Found"<<endl; else cout<<"The No. is at"<<i+1<<"positionn"; } void InsertIntoList() { cout<<"Enter the no. to insertn"; cin>>insert_number; cout<<"Enter the positionn"; cin>>position_to_insert; for(i=total_elements-1;i>=position_to_insert-1;i--) { list[i+1]=list[i]; } list[position_to_insert-1]=insert_number; total_elements++; } void DisplayList()
  • 3.