0% found this document useful (0 votes)
51 views

Lab 5 Data Structure and Algoritm

This document contains C++ code that implements a queue data structure using an array. The code defines functions for inserting elements into the queue, deleting elements from the queue, and displaying all elements currently in the queue. The main function uses a do-while loop to display a menu and call the appropriate queue function based on the user's input choice until they choose to exit.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views

Lab 5 Data Structure and Algoritm

This document contains C++ code that implements a queue data structure using an array. The code defines functions for inserting elements into the queue, deleting elements from the queue, and displaying all elements currently in the queue. The main function uses a do-while loop to display a menu and call the appropriate queue function based on the user's input choice until they choose to exit.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

NEIL ALEXIS R.

GABRIEL
BSCS 2 (BLK – 1)
LABORATORY ACTIVITY NUMBER 5
DATA STRUCTURES AND ALGORITHMS

CODE:

#include <iostream>

using namespace std;

int queue[100], n = 100, front = - 1, rear = - 1;

void Insert() {

int val;

if (rear == n - 1)

cout<<"Queue Overflow"<<endl;

else {

if (front == - 1)

front = 0;

cout<<"Insert the element in queue : ";

cin>>val;

rear++;

queue[rear] = val;

void Delete() {

if (front == - 1 || front > rear) {

cout<<"Queue Underflow ";

return ;

} else {

cout<<"Element deleted from queue is : "<< queue[front] ;

front++;;

}
}

void Display() {

if (front == - 1)

cout<<"Queue is empty"<<endl;

else {

cout<<"Queue elements are : ";

for (int i = front; i <= rear; i++)

cout<<queue[i]<<" ";

cout<<endl;

int main() {

int ch;

cout<<"1) Insert element to queue"<<endl;

cout<<"2) Delete element from queue"<<endl;

cout<<"3) Display all the elements of queue"<<endl;

cout<<"4) Exit"<<endl;

do {

cout<<"\nEnter your choice : ";

cin>>ch;

switch (ch) {

case 1: Insert();

break;

case 2: Delete();

break;

case 3: Display();

break;

case 4: cout<<"Exit";

break;
default: cout<<"\nInvalid choice"<<endl;

} while(ch!=4);

return 0;

OUTPUT:

You might also like