-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnodeStack.cpp
More file actions
50 lines (46 loc) · 930 Bytes
/
nodeStack.cpp
File metadata and controls
50 lines (46 loc) · 930 Bytes
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
#include "nodeStack.h"
// #include <iostream>
void pop1(nodeStackPtr& head, int currLoc[])//copies the location info to call by ref array, then deletes top of stack
{
currLoc[0] = head->row;
currLoc[1] = head->col;
nodeStackPtr toDelete = head;
head = head->link;
delete toDelete;
}
void pop1(nodeStackPtr& head)//deletes top of stack
{
nodeStackPtr toDelete = head;
head = head->link;
delete toDelete;
}
bool isLLempty(nodeStackPtr& head)
{
return !head;
}
void emptyStack(nodeStackPtr& head)
{
while(!isLLempty(head))
{
pop1(head);
}
}
void push1(nodeStackPtr& head, int loc[])
{
if(isLLempty(head))
{
head = new nodeStack;
head->link = nullptr;
head->row = loc[0];
head->col = loc[1];
}
else
{
nodeStackPtr temp_ptr;
temp_ptr = new nodeStack;
temp_ptr->row = loc[0];
temp_ptr->col = loc[1];
temp_ptr->link = head;
head = temp_ptr;
}
}