-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchain_Queue.hpp
102 lines (84 loc) · 1.72 KB
/
chain_Queue.hpp
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//
// chain_list.hpp
// double_link_list
//
// Created by Eric on 2017/10/22.
// Copyright © 2017年 Eric. All rights reserved.
//
#ifndef chain_Queue_hpp
#define chain_Queue_hpp
//#include <stdio.h>
#include <iostream>
template<class type>
class chainNode
{
public:
template<class type2>
friend class stackList;
template<class type3,class type4,class type5>
friend class circList;
protected:
chainNode *next;
type value;
};
template<class type>
struct Node
{
Node *next;
type value;
};
template<class type>
class chainQueue
{
//template<class T>
public:
//friend class chainNode;
chainQueue(){};
//template<class type>
chainQueue(type data):capacity(data){
Node<type> *link=new Node<type>;
link->value=data;
head=link;
link->next=0;
};
//template<class type>
void insertFront(type data){
Node<type> *link=new Node<type>;
link->value=data;
link->next=head;
head=link;
};
Node<type> *top(){
return head;
};
void reverse(){
Node<type> *curr=head;Node<type> *prev=0;
//last=head;
while(!curr)
{
Node<type> *temp=prev;
prev=curr;
curr=curr->next;
prev->next=temp;
}
head=prev;
};
void show()
{
Node<type> *ptr=head;
while(ptr->next)
{
std::cout<<ptr->value<<std::endl;
ptr=ptr->next;
}
std::cout<<ptr->value<<std::endl;
};
private:
//template<class type>
Node<type> *head;
Node<type> *last;
//int stackCapacity;
int capacity;
//chainNode *head;
};
#endif /* chain_list_hpp */