-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path16.cpp
More file actions
58 lines (46 loc) · 972 Bytes
/
16.cpp
File metadata and controls
58 lines (46 loc) · 972 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
51
52
53
54
55
56
57
58
#include <iostream>
using namespace std;
struct Queue{
int val;
int size;
Queue *Head,*Tail,*Next;
void Add(const int x);
void Show(const int count);
void Del();
};
void Queue::Add(int x){
static int count=0;
Queue *temp = new Queue;
temp->val=x;
if (Head!=NULL){
Tail->Next=temp;
Tail=temp;
} else Head=Tail=temp;
count++;
size=count;
Tail->Next=Head;
}
void Queue::Show(const int count){
Queue *temp=Head;
for (int i=0;i<count;i++){
cout<<temp->val<<" ";
temp=temp->Next;
} cout<<endl;
}
void Queue::Del(){
Queue *temp=new Queue;
int count=0;
while (temp!=Tail){
temp=Head;
Head=Head->Next;
delete temp;
}
}
int main(){
Queue Q;
Q.Head=NULL;
for (int i=0;i<10;i++)
Q.Add(rand());
Q.Show(10);
Q.Del();
}