Write the array implementation of a list.
Requirements:
1)create class
2)No global declarations
3) functions
Isempty()
Delete()
Insert()
Display()
4)Call the functions in main
#include <iostream>
using namespace std;
int a,arr[20],n,e;
void Delete()
{
int n;
cout<<"\nEnter element to delete:\n";
cin>>n;
for(int i=0;i<n;i++)
{
if(arr[i]==n)
{
arr[i]=0;
cout<<n<<" deleted";
}
}
}
void create()
{
cout<<"\n Enter the number of elements to create: "; cin>>n;
cout<<"\nEnter the elements\n";
for(int i=0;i<n;i++)
{
cin>>arr[i];
}
}
void display(){
for(int i=0;i<n;i++)
{
cout<<"\n"<<arr[i];
}
}
void insert()
{
int n;
cout<<"\nEnter number of elements to insert: ";
cin>>n;
cout<<"\nEnter the elements\n";
for(int i=0;i<n;i++){
cin>>arr[n++];
}
}
int main()
{
int c;
cout<<"\n1. Create \n2. Delete \n3. Insert \n4. Display \n5. Exit";
do
{
cout<<"\nEnter your choice:";
cin>>c;
switch(c)
{
case 1:
create();
break;
case 2:
Delete();
break;
case 3:
insert();
break;
case 4:
display();
break;
case 5:
exit(0);
break;
default:
cout<<"Invalid Input\n";
}
}
while(c<=6);
return 0;
}
Comments
Leave a comment