C++ Programming Tutorial

 
 
 

Data File Structure Programs

Array

Insert, edit, delete, append, display, Srch. Insert, delete, merge, delete multiple occurrences Arrays as a Stack in graphics

Stack

Stack operations using array Stack using static memory allocation Stack using dynamic memory allocation Double ended link list as a stack Lnked list as a Stack Infix expr. to Postfix expr. Postfix expr. into an Infix expr. Arrays as a Stack in graphics Stack as an Arithmetic expr. Evaluater Graphical Rep. of Stack Stack to traverse - inodr, postodr, preodr

Queue

Queue using static memory allocation Queue using dynamic memory allocation Circular queue Linked list as a Queue Double Ended linked list as a Queue Graphical Rep. of Queue Arrays as a Linear Queue Array as a Circular Queue Arrays as a Linear Queue ( in graphics ) Arrays as a Circular Queue ( in graphics )

Linked List

Singly link list Circular linked list Doubly link list Linked list as a Queue Linked list as a Stack Double Ended linked list as a Queue Double Ended linked list as a Stack Infix to Postfix - Linked List as Stack Circular doubly link list Single Ended Linked List - Sorting in both odr Hashing - double ended Linked List Sort of link list

Tree

Linked List as a Binary Srch. Tree Set Class using Binary Srch. Tree Maximum depth of Binary Srch. Tree Minimum Spaning Tree Prims algo - minimum spanning tree Traverse binary tree - inodr, preodr, post Find number in binary Srch. tree display levell

Sorting

Bubble Sort Selection Sort Insertion Sort Radix Sort Merge Sort Quick Sort Heap Sort Linear Sort Shell Sort Topological Sort

Searching

Linear Srch. or Sequential Srch. Binary Search Breadth First Search Traversal Depth First Search Traversal Shortest Path-Given Source-Destination-Dijkstras

Hashing

Simple implementation of Hashing Hashing using double-ended Linked List Hashing using Mid-Square Method Example of Hashing n term of the fibonacci series using recursion

Recursion

Factorial of the given number using recursion Mystery of Towers of Hanoi using recursion
 
 
 #include <iostream.h>
 #include    <conio.h>

 const max_length=10;

 class Queue
    {
       private:
      int queue[max_length];
      int rear;
      int front;

       public:
      Queue( );

      void Delete( );
      void Insert( );
      void print_queue( );
      void show_working( );
    };


 //--------------------------  Queue( )  ---------------------------------//


 void Queue::Queue( )
    {
       rear=-1;
       front=-1;

       for(int count=0;count<max_length;count++)
      queue[count]=0;
    }


 //------------------------------  Insert( )  ----------------------------//


 void Queue::Insert( )
    {
       int item;

       cout<<\"\\n\\n\\n\\n\\n\\t Enter value to insert into the Queue : \";
       cin>>item;

       if((rear==front-1) || (front==0 && rear==max_length-1))
      cout<<\"\\n\\n\\t ***  Error : Queue is full. \\n\"<<endl;

       else if(rear==-1 && front==-1)
      {
         rear++;
         queue[rear]=item;
         front=rear;

         cout<<\"\\n\\n\\t *** \"<<item<<\" is inserted into the Queue.\"<<endl;
      }

       else if(rear==max_length-1 && front!=0)
      {
         rear=0;
         queue[rear]=item;

         cout<<\"\\n\\n\\t *** \"<<item<<\" is inserted into the Queue.\"<<endl;
      }

       else
      {
         rear++;
         queue[rear]=item;

         cout<<\"\\n\\n\\t *** \"<<item<<\" is inserted into the Queue.\"<<endl;
      }

       cout<<\"\\n\\n\\n\\t\\t Pres any key to return to Menu. \";

       getch( );
    }


 //------------------------------  Delete( )  ----------------------------//


 void Queue::Delete( )
    {
       if(rear==-1 && front==-1)
      cout<<\"\\n\\n\\n\\t ***  Error : Queue is empty. \\n\"<<endl;

       else
      {
         cout<<\"\\n\\n\\n\\t *** \"<<queue[front]<<\" is deleted from the Queue.\"<<endl;

         queue[front]=0;

         if(front==rear)
        {
           front=-1;
           rear=-1;
        }

         else if(front==max_length-1)
        front=0;

         else
        front++;
      }

       cout<<\"\\n\\n\\n\\t\\t Pres any key to return to Menu. \";

       getch( );
    }


 //---------------------------  print_queue( )  --------------------------//


 void Queue::print_queue( )
    {
       if(front!=-1 && rear!=-1)
      {
         cout<<\"\\n\\n\\n\\n\\n\\t Values inserted into the Queue are : \\n\"<<endl;

         for(int count=0;count<max_length;count++)
        cout<<\"\\t Stack [\"<<count<<\"]  =  \"<<queue[count]<<endl;
      }

       else
      cout<<\"\\n\\n\\n\\n\\n\\t *** Nothing to show. \"<<endl;

       cout<<\"\\n\\n\\n\\t\\t Pres any key to return to Menu. \";

       getch( );
    }



 //-------------------------  show_working( )  ---------------------------//


 void Queue::show_working( )
    {
       char Key=NULL;

       do
      {
         clrscr( );

         gotoxy(5,5);
         cout<<\"**********   Implementation of Array as Circular Queue   **********\"<<endl;

         gotoxy(10,8);
         cout<<\"Select one of the listed operation :\"<<endl;

         gotoxy(15,10);
         cout<<\"- Press \\\'I\\\' to Insert a value\"<<endl;

         gotoxy(15,12);
         cout<<\"- Press \\\'D\\\' to Delete a value\"<<endl;

         gotoxy(15,14);
         cout<<\"- Press \\\'P\\\' to Print the values\"<<endl;

         gotoxy(15,16);
         cout<<\"- Press \\\'E\\\' to Exit\"<<endl;

         Input:

         gotoxy(10,20);
         cout<<\"                      \";

         gotoxy(10,20);
         cout<<\"Enter your Choice : \";

         Key=getche( );

         if(int(Key)==27 || Key==\'e\' || Key==\'E\')
        break;

         else if(Key==\'i\' || Key==\'I\')
        Insert( );

         else if(Key==\'d\' || Key==\'D\')
        Delete( );

         else if(Key==\'p\' || Key==\'P\')
        print_queue( );

         else
        goto Input;
      }
       while(1);
    }

 int main( )
    {
       Queue obj;

       obj.show_working( );

       return 0;
    }

    Related Post:
  1. Scanner of valide variable name in c

  2. Program of class to class conversion

  3. Program to read n integers and add them up and output the result

  4. Program to draw a line using Bresenhams Line Algorithm (BLA) for lines with slopes positive and greater than 1

  5. Program of KSCANNER

  6. Program that uses this DFA and validates whether an entered string is valid integer or not.

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

  8. Program that take font and background color and text input from a user and display it in center aligned

  9. Program to show the projection of 3D objects using Orthographics Projection Parallel onto xy-plane

  10. Program which read device data from a text file and show each extension\’s dues

  11. Program that will read a token from a user and find its type

  12. Program to read a Linear System of Equations,then evaluate it by using Guass-Seidel Itrative Method and show the result

  13. Stacks code in C++

  14. Program to calculate distance summation, subtraction, multiplication and comparison using overloading operators also make it friend functions

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

  16. Program to show the use of Bitwise Operator Left Shift ( &lt;&lt; )

  17. Program to implement Add and Subtract function on Big Number Class

  18. Program to illustrate the implementation of 3D Rotation Transformation along z-axis

  19. Program to create a circular linked list

  20. Program of Deapth First Search Traversal ( DFS )

 
 
Didn't find what you were looking for? Find more on Program to illustrate the implementation of array as a Circular Queue