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