C++ Programming Blog

 
 
 

Image

#include <iostream.h>
#include <conio.h>

int top=-1;
const int bottom=0;
int q_arr[10];

void insert(void)
{
  if(top==-1)
    cout<<\"\\n\\nList is Empty\\n\\n\";
  if(top==10)
  {
    cout<<\"\\nList overflow\\n\";
    goto out;
  }
  cout<<\"\\nEnter info to be inserted:-\";
  cin>>q_arr[top+1];
  top=top+1;
out:
}

void del(void)
{
int c=0;
  if(top==-1)
  {
    cout<<\"\\n\\nList Underflow\\n\";
    goto out;
  }
  cout<<\"\\n\\nInfo which is deleted by you is \"<<q_arr[bottom];
     while(c<top)
   {
     q_arr[c]=q_arr[c+1];
     c++;
   }
   top=top-1;
out:
}

void main()
{
 clrscr();
 int choice;
 while(1)
 {
 cout<<\"\\n\\n\\nChoose your choice\\n\";
 cout<<\"1)  Insert element\\n\";
 cout<<\"2)  Delete element\\n\";
 cout<<\"3)  Exit\\n\";
 cout<<\"Enter your choice:-\";
 cin>>choice;
   switch(choice)
   {
     case 1 : insert();
               break;
     case 2 :  del();
               break;
     case 3 :  goto out;
     default: cout<<\"\\n\\nEntered Info is Invalid\\nTry again\\n\\n\";
   }
}
out:
}

 
 
Didn't find what you were looking for? Find more on Program to create a queue using static memory allocation