0% found this document useful (0 votes)
267 views3 pages

Write C++ Programs To Implement The Queue ADT Using A Singly Linked List

This C++ program implements a queue using a singly linked list. It defines a node class to store data and pointers, and a queue class that contains a head pointer and methods to push, pop, and display elements. The main function contains a menu loop that allows the user to push, pop, or display elements in the queue and handles overflow and underflow conditions.

Uploaded by

sreeja1992
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
267 views3 pages

Write C++ Programs To Implement The Queue ADT Using A Singly Linked List

This C++ program implements a queue using a singly linked list. It defines a node class to store data and pointers, and a queue class that contains a head pointer and methods to push, pop, and display elements. The main function contains a menu loop that allows the user to push, pop, or display elements in the queue and handles overflow and underflow conditions.

Uploaded by

sreeja1992
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

/* Write C++ programs to implement the Queue ADT using a singly linked list */ #include<iostream> #include<conio.h> #include<stdlib.

h> using namespace std; class node { public: class node *next; int data; }; class queue : public node { node *head; int front,rare; public: queue() { front=-1; rare=-1; } void push(int x) { if (rare < 0 ) { head =new node; head->next=NULL; head->data=x; rare ++; } else { node *temp,*temp1; temp=head; if(rare >= 4) { cout <<"queue over flow"; return; } rare++; while(temp->next != NULL) temp=temp->next; temp1=new node; temp->next=temp1; temp1->next=NULL;

temp1->data=x; } } void display() { node *temp; temp=head; if (rare < 0) { cout <<" queue under flow"; return; } while(temp != NULL) { cout <<temp->data<< " "; temp=temp->next; } } void pop() { node *temp; temp=head; if( rare < 0) { cout <<"queue under flow"; return; } if(front == rare) { front = rare =-1; head=NULL; return; } front++; head=head->next; } }; main() { queue s1; int ch; while(1) { cout <<"\n1.PUSH\n2.POP\n3.DISPLAY\n4.EXIT\n enter ru choice:"; cin >> ch; switch(ch)

{ case 1: cout <<"\n enter a element"; cin >> ch; s1.push(ch); break; case 2: s1.pop();break; case 3: s1.display();break; case 4: exit(0); } } return (0); } OUTPUT 1.PUSH 2.POP 3.DISPLAY 4.EXIT enter ru choice:1 enter a element23 1.PUSH 2.POP 3.DISPLAY 4.EXIT enter ru choice:1 enter a element54 1.PUSH 2.POP 3.DISPLAY 4.EXIT enter ru choice:3 23 54 1.PUSH 2.POP 3.DISPLAY 4.EXIT enter ru choice:2 1.PUSH 2.POP 3.DISPLAY 4.EXIT enter ru choice:2 1.PUSH 2.POP 3.DISPLAY 4.EXIT enter ru choice:2 queue under flow 1.PUSH 2.POP 3.DISPLAY 4.EXIT enter ru choice:4

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy