-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcircularList.hpp
More file actions
70 lines (60 loc) · 1.45 KB
/
circularList.hpp
File metadata and controls
70 lines (60 loc) · 1.45 KB
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
//
// circularList.hpp
// double_link_list
//
// Created by Eric on 2017/10/25.
// Copyright © 2017年 Eric. All rights reserved.
//
#ifndef circularList_hpp
#define circularList_hpp
#include <iostream>
#include "chainStack.hpp"
template<class type,class type2,class type3>
class circList:public chainQueue<type2>,stackList<type3>
{
//template<class T>
public:
//friend class chainNode;
circList(){};
//template<class type>
circList(type data){
chainNode<type> *link=new chainNode<type>;
link->value=data;
last=head=link->next=link;
};
//template<class type>
void insertFront(type data){
chainNode<type> *link=new chainNode<type>;
link->value=data;
link->next=head;
last->next=head=link;
};
void reverse(){
chainNode<type> *curr=head;chainNode<type> *prev=last;
//last=head;
do
{
chainNode<type> *temp=prev;
prev=curr;
curr=curr->next;
prev->next=temp;
}while(curr!=head);
head=prev;
};
void show()
{
chainNode<type> *ptr=head;
while(ptr->next!=head)
{
std::cout<<ptr->value<<std::endl;
ptr=ptr->next;
}
std::cout<<ptr->value<<std::endl;
};
private:
//template<class type>
chainNode<type> *head;
chainNode<type> *last;
//chainNode *head;
};
#endif /* circularList_hpp */