PROGRAM OF QUEUE USING C++ Gain Infiniti

PROGRAM OF QUEUE USING C++


#include <iostream>
using namespace std;
#define size 10

class queue
{
    public:
    int first,last;
    int info;
    int array[size];
    queue()
    {
        first=last=-1;
    }
    void qInsert(int el)
    {
        if(last==size-1)
        {
cout<<"QUEUE FULL !";
        }
        else if(first==-1)
        {
            array[++last]=el;
            first++;
        }
        else
        array[++last]=el;
    }
    void qDelete()
    {
        if(first == -1)
        cout<<"QUEUE EMPTY !";
        else
        {
            first++;
        }
    }
    void display()
    {
        for(int i=first;i<last;i++)
        cout<<array[i]<<"->";
        cout<<array[last];
        cout<<endl;
    }
};

main()
{
    queue list;
    list.qInsert(10);
    list.qInsert(20);
    list.qInsert(30);
    list.qInsert(40);
    list.display();
    list.qDelete();
    list.qDelete();
    list.display();
}
       
/*OUTPUT

10->20->30->40
30->40

*/

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 

Design By Manish and Ranjan