C++ Programming Blog

 
 
 

Image

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

struct link_list
{
 int no;
 struct link_list *next;
};
class queue
{
 link_list *list,*head;
 public:
    queue()
    {
     head=NULL;
     free(list);
    }
    void insert();
    void display();
    void delete_element();
};

void queue :: insert()
{
  link_list *newnode;
  newnode=new link_list;
  cout<<\"Enter Number to Insert :\";
  cin>>newnode->no;
  list=head;
  if(head==NULL)
  {
    head=newnode;
    newnode->next=NULL;
  }
  else
  {
    newnode->next=list;
    list=newnode;
    head=newnode;
  }
}

void queue :: display()
{
 cout<<endl;
  if(head==NULL)
 {
  cout<<\"Empty Queue !!!\";
  return;
 }
 list=head;
 while(list!=NULL)
 {





  cout<<list->no<<\"\\t\";
  list=list->next;
 }
}

void queue :: delete_element()
{
 cout<<endl;
 if(head==NULL)
 {
  cout<<\"Empty Queue !!!\";
  return;
 }
 else
 {
  list=head;

  if(list->next==NULL)
  {
    cout<<\"Deleted Element : \"<<list->no<<endl;
    head=NULL;
    delete(list);
    list=NULL;
    return;
  }
  while(list->next->next!=NULL)
  {
   list=list->next;
  }
  cout<<\"Deleted Element : \"<<list->next->no<<endl;
  delete(list->next);
  list->next=NULL;
 }
}
int display_menu()
{
 int ch;
 clrscr();
 cout<<endl;
 cout<<\"[ 1 ] Insert\"<<endl;
 cout<<\"[ 2 ] Delete\"<<endl;
 cout<<\"[ 3 ] Display\"<<endl;
 cout<<\"[ 4 ] Exit\"<<endl;
 cout<<\"Enter your choice :\";
 cin>>ch;
 return ch;
}
void main()
{
queue q1;
 while(1)
 {
  switch(display_menu())
  {
   case 1:q1.insert();
      break;
   case 2:q1.delete_element();
      getch();
      break;
   case 3:q1.display();
      getch();
      break;
   case 4: exit(1);
  }
 }
}

    Related Post:
  1. Program to draw an Ellipsoid using Parametric Equations

  2. Program that reads a numbers , computes and displays the factorial of the given number using recursion

  3. Program of class to basic conversion

  4. Program to construct and display the Divided Difference Table from the given distinct data points.

  5. Program to illustrate the implementation of Rotation Transformation

  6. Program that provides an example of binary files

  7. Program to draw a circle using MidPoint Circle Algorithm

  8. Program to estimate the value of Fourth Derivative of the function at the given points from the given data using Central Difference Formula of order 4

  9. Program to implement Add and Subtract functions on Big Number Class

  10. Program to illustrate the binary operator(-) overloading without creating an object of that class

  11. Program of nesting member functions, private member functions and array of objects

  12. Program of Shortest Path for Given Source and Destination (using Dijkstras Algo.)

  13. File Operation Program

  14. Program to estimate the Integral value of the function at the given points from the given data using Simpsons 1/3 Rule

  15. Program to illustrate static member functions

  16. Program to illustrate the use of parameterless function

  17. Program to illustrate pointers and an array of structure

  18. Program to illustrate the implementation of Arithmetic Expression Evaluater accepting {} & [] also

  19. Program to implement the Prims Algorithm to solve Minimum Spanning Tree Problem (MST) using Graphics and with Mouse support

  20. Program to show the use of Bitwise Operator Right Shift ( &gt;&gt; )

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