Circular Queue Dengan Linked List

#include<iostream>
#include<conio.h>
#include<process.h>
using namespace std;
class circlst                 //Class Declaration
{
   private:
       struct node
           { int info;             //Node Structure
         node *next;
           }*ptr,*first,*last,*track;
   public:
       circlst()                       //Constructor
       {ptr=first=last=track=NULL;}
       void insrt(int);
       void delnde();
       void displst();      //Memeber Functions
};
void circlst::insrt(int n)
{
  ptr=new node;
     if(ptr==NULL)
    { cout<<"\nNode Cannot Be Created!!!";
      getch();
      exit(0);
    }
   ptr->info=n;
   ptr->next=ptr;            //Function To Insert Node

   if(first==NULL)
      first=last=ptr;
   else
      { last->next=ptr;
    ptr->next=first;
    last=ptr;
      }
}
void circlst::delnde()
{   if(first==NULL)
      { cout<<"\nThe List Is Empty!!!";
    getch();
    exit(0);
      }                           //Function To Delete Node
  first=first->next;
  last->next=first;
  cout<<"\n\nNode Deleted Succesfully!!!";
}
void circlst::displst()
{ track=first;
  if(first==NULL)
     cout<<"\nThe List Is Empty!!!";
  while((track->next)!=first)
    {                                  //Function To Delete Node
      track=track->next;
      cout<<track->info<<" ";
    }
}
int main()                     //Main
{
  circlst ob;
  char choice;
  int data,ch;
  do
  {
    system ("cls");
    cout<<"\n\n\t\tCREATION OF A CIRCULAR LINKED LIST";
    cout<<"\n\t\t---------------------------------";
    cout<<"\n\n1.INSERT ELEMENT";
    cout<<"\n2.DISPLAY LIST";
    cout<<"\n3.DELETE ELEMENT";         //menu
    cout<<"\n4.EXIT";
    cout<<"\n\nWhich Operation Do You Want To Perform : ";
    cin>>ch;
     switch(ch)
          {
         case 1: cout<<"\nEnter the Data To Be Inserted : ";
             cin>>data;
             ob.insrt(data);
             break;
         case 2: ob.displst();
             break;             //calling functions
         case 3: ob.delnde();
             break;
         case 4: exit(1);
         default: cout<<"\nPleasae Enter A valid Choice(1-4)!!!";
           }
    cout<<"\n\nDo you Want to Continue(Y/N) : ";
    cin>>choice;
   }while(choice=='Y' || choice=='y');
}                   //end of program

Comments

Populer

Full Modul Kuliah "Teknik Informatika" Universitas Pamulang - UNPAM

Luas dan Keliling Segitiga, Persegi Panjang, dan Lingkaran

Full Modul Kuliah "Teknik Informatika"