Skip to content

Commit f97e0d1

Browse files
committed
added queue in data stucture, modified stack to delete the memory of stack via destructor
1 parent 5cc9a9e commit f97e0d1

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

CPP/Data Structures/queue/queueClass.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ class Queue {
1414
Queue(int capacity = 10) {
1515
this->capacity = capacity;
1616
sz = 0;
17-
head = -1;
18-
tail = -1;
17+
head = 0;
18+
tail = 0;
1919
arr = new T[capacity];
2020
}
2121

@@ -28,14 +28,14 @@ class Queue {
2828
}
2929

3030
bool full() {
31-
return tail == capacity;
31+
return sz == capacity;
3232
}
3333

3434
void resize(int cap) {
3535
if(cap < 1) cap = 1;
3636
T* narr = new T[cap];
3737

38-
for(int i=head; i<tail; i++)
38+
for(int i=0; i<sz; i++)
3939
narr[i] = arr[(head + i) % capacity];
4040
delete []arr;
4141
arr = narr;
@@ -69,8 +69,8 @@ class Queue {
6969
}
7070

7171
void display() {
72-
for(int i=head; i<=tail; i++) {
73-
cout << arr[i] << " ";
72+
for(int i=0; i<sz; i++) {
73+
cout << arr[(head + i) % capacity] << " ";
7474
}
7575
cout << endl;
7676
}

0 commit comments

Comments
 (0)