Dequeue Assignment PDF
Document Details
Uploaded by UnlimitedPhotorealism4633
MTI University
Tags
Summary
This document is a code example implementing a queue data structure. It demonstrates the enqueue and dequeue operations and includes functions for checking emptiness and fullness of the queue. The code is written in C++ using an array-based approach.
Full Transcript
Dequeue Assignment #include using namespace std; const unsigned int maxlength = 100; struct Queue { char s[maxlength]; int top =-1; void reset (Queue *stk) { stk-> top = -1; } void enqueue(char c,Queue *stk) { stk -> top++; stk -> s[stk -> top]=c; } char dequeue(Queue *...
Dequeue Assignment #include using namespace std; const unsigned int maxlength = 100; struct Queue { char s[maxlength]; int top =-1; void reset (Queue *stk) { stk-> top = -1; } void enqueue(char c,Queue *stk) { stk -> top++; stk -> s[stk -> top]=c; } char dequeue(Queue *stk) { char c = stk -> s; for (int i = 0; i < stk->top; i++) { stk -> s[i] = stk -> s[i+1]; } stk -> top --; return c; } bool empty (Queue *stk) { if (stk->top == -1) return(true); else return (false); } bool full (Queue *stk) { if (stk->top == maxlength - 1) return(true); else return(false); } void display() const { cout