-
Notifications
You must be signed in to change notification settings - Fork 0
/
Queue.cpp
53 lines (43 loc) · 940 Bytes
/
Queue.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "Queue.h"
#include <string>
#include <iostream>
using namespace std; // Needed for cout, cin to be recognized
//Default Queue
Queue::Queue(){
elementCount = 0;
head = NULL;
tail = NULL;
}
int Queue::getElementCount(){
return(elementCount);
}
bool Queue::isEmpty(){
if(getElementCount() == 0)
{
return(true);
}
else
{
return(false);
}
}
///!!!!!!!!!!!!!!!!!!!!!!!FOR NOW IT IS INT REMEMBER TO CHANGE BACK TO ORIGINAL!!!!!!!!!!!!!!!!!!!!!!?????/////
//bool Queue::enqueue(const ElementType& newElement)
bool Queue::enqueue(const int newElement){
Node *newNode = new Node(newElement);
if(head == NULL){ //For the case it is empty
head = newNode;
tail = newNode;
}
else{
tail->next = newNode; //Inserting at the end of LL
tail = newNode; //updating tail
}
}
bool Queue::dequeue()
{
Node* current = head;
head = head->next;
delete current;
}
//Not doing peek cause dont know execptions yet...