my queue

 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
54
55
56
57
58
59
60
61
#include <iostream>
#include <stdlib.h>
struct qnode {
int value;
qnode* next;
};
void insertNode(qnode*& ntop, int nvalue) {
qnode* newNode = new qnode;
newNode->value = nvalue;
if(ntop == NULL) {
ntop = newNode;
} else {
newNode->next = ntop;
ntop = newNode;
}
delete newNode;
}
void npop(qnode*& ntop) {
if (ntop == NULL) {
exit(0);
}
if (ntop->next == NULL) {
ntop = NULL;
} else {
npop(ntop->next);
}
}
void nvisit(qnode* ntop) {
if(ntop == NULL) {
std::cout<<"end.";
} else {
std::cout<<ntop->value<<"->";
nvisit(ntop->next);
}
}
void last(qnode* ntop) {
qnode* last = ntop;
while (last->next != NULL) {
last = last->next;
}
std::cout<<last->value<<std::endl;
}
int main() {
qnode* mquque = new qnode;
mquque->value = 12;
insertNode(mquque, 23);
insertNode(mquque, 31);
//nvisit(mquque);
last(mquque);
//npop(mquque);
//last(mquque);
delete mquque;
return 0;
}