nie-ii-year

lab stuff from undergrad second year.
git clone http://git.hanabi.in/repos/nie-ii-year.git
Log | Files | Refs | LICENSE

commit ccafde8142524a448c77cd229d1c2657fa2d1fca
parent b3d9cc1e76058f6ab5b5ca512c883611f4766fd1
Author: Agastya Chandrakant <acagastya@outlook.com>
Date:   Fri,  3 Nov 2017 10:36:00 +0530

let's see
Diffstat:
As3/oops/tq2.cpp | 63+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 63 insertions(+), 0 deletions(-)

diff --git a/s3/oops/tq2.cpp b/s3/oops/tq2.cpp @@ -0,0 +1,63 @@ +#include <iostream> +#define MAX 5 + +int read = -1; +int write = -1; + +class queue{ +template <class T> + T data[MAX]; +public: +template <class T> + void inQueue(){ + T incoming; + if(write == MAX - 1){ + std::cout << "Queue overflow\n"; + return; + } + if(read == -1) + ++read; + std::cout << "Enter element to be entered: "; + std::cin >> incoming; + write = (write + 1); + data[write] = incoming; + }; + template <class T> + void deQueue(){ + if(read == -1 || read > write) + std::cout << "Queue underflow.\n"; + else{ + std::cout << data[read] << " has been removed.\n"; + read++; + } + }; + template <class T> + void displayQueue(){ + if(write == -1 || read > write) + std::cout <<"Queue is empty.\n"; + else{ + for(int i = read; i <= write; i++) + std::cout << data[i] << " "; + std::cout << "\n"; + } + }; +}; + +int main() { + int choice; + queue <int> q; + do{ + std::cout << "Enter choice: "; + std::cin >> choice; + switch (choice) { + case 1: q.inQueue(); + q.displayQueue(); + break; + case 2: q.deQueue(); + q.displayQueue(); + break; + default: choice = 0; + } + }while(choice); + return 0; +}