Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Stack and Queue Data Structures: Implementation and Examples in C++, Slides of Computer Programming

A comprehensive overview of stack and queue data structures, fundamental concepts in computer science. It delves into their implementation using arrays and linked lists in c++, illustrating their functionalities with code examples. The document also explores the limitations of traditional queues and introduces the concept of circular queues, enhancing efficiency in data management.

Typology: Slides

2020/2021

Available from 02/02/2025

the-manku-store
the-manku-store 🇮🇳

8 documents

1 / 9

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Stack and Queue
pf3
pf4
pf5
pf8
pf9

Partial preview of the text

Download Stack and Queue Data Structures: Implementation and Examples in C++ and more Slides Computer Programming in PDF only on Docsity!

Stack and Queue

Stack

#define maxSize 5 struct Stack{ int top=-1; int data[maxSize]; }s; void push(int a) { if(!overFlow()) { s.data[++s.top]=a; } else cout<<“stack overflow!!!”; } int pop() { if(!underFlow(s)) { return(s.data[s.top--]); } else cout<<“Stack is already empty”; } int overFlow() { if(s.top==maxSize-1) return(1); else return(0); }

Linked List Implementation of Stack

top

2 3 5

Queue

void enqueue(int a){ If(!Full(q)) q.data[++q.rear]=a; else cout<<“Queue is full”; } int dequeue(){ If(!isEmpty()) return(q.data[q.front++]); else { cout<<“Queue is empty”; exit(0); } }

  • #define maxSize 5
  • struct queue{ int front=0; int rear=-1; int data[maxSize]; }q; int Full() { if(rear==maxSize-1) return(1); else return(0); }

Linked List Implementation of Queue

Rear

front

5 2 1

Circular Queue

  • Limitation of Queue:-

front

rear

0 1 2 3 4 5 Queue is Empty still we can not insert data!!!