📄 header1.h
字号:
#ifndef HEADER_Header1
#define HEADER_Header1
#define null 0
#include <assert.h>
const int DefaultDataValue=0;//define const varible data for the node which doesn't provide data value;
template <class Type> class Circlist;
template <class Type> class CirclistNode{//define class circlistnode
friend class Circlist<Type>;//make class circlist the friend element of circlistnode so that it can visit the private attribute indirectly.
private:
Type data;//data value
CirclistNode<Type>* link;//next node's address
public:
CirclistNode(const Type& value_Data,CirclistNode<Type>* value_Link=null){
data=value_Data;
link=value_Link;
}
void SetData(Type& otherData)const{
data=otherData;
}
Type GetData()const{
return data;
}
void SetLink(CirclistNode<Type>& value_Link)const{
link=value_Link;
}
CirclistNode<Type>* GetLink()const{
return link;
}
CirclistNode<Type>& operator=(CirclistNode<Type>& otherNode) const{
data=otherNode.GetData();
link=otherNode.GetLink();
return *this;
}
};
template <class Type> class Circlist{ //define class circle link with single direction
private:
CirclistNode<Type> *First,*Current; //define the pointer to header,the pointer pointing to current node position .
public:
Circlist(Type& HeadValue){
Current=First=new CirclistNode<Type>(HeadValue); //initialize the first, current node pointer
assert(First);
First->link=First;
}
~Circlist();
CirclistNode<Type>* GetCurrent()const{
return Current;
}
CirclistNode<Type>* GetFirst()const{
return First;
}
int GetLength()const; //return the length of circlist
bool IsEmpty()const; //judge the circlist empty or not
CirclistNode<Type>* Find(const Type& value); //search the node based on given value
bool SetCurrent(int i); //make current pointer pointed to the node given by position
void InsertNode(const Type& DataValue); //insert a new node to current pointer's next node
bool DelCurrentNode(); //delete the node's next node pointed by current pointer
void Firster(); //make current pointer the header node
bool LocateFirst(); //make current pointer pointed to the first node of circlist
bool Next(); //make current pointer pointed to the next node
bool Prior(); //make current pointer pointed to the prior node
void ShowAllElement(); //show all elements in current list
};
template <class Type> class CirclJosephus_List:public Circlist<Type>{
//class circle is defined here, it inherit class circlist many basic manipulations and convient to be used,
//when it work,the Josephus problem will be sorted out through using high abstract methods.
private:
const int Number;
const int StartNumber;
const int PeopleNumber;
public:
CirclJosephus_List(Type headValue,int value_Number,int value_StartNumber,int value_PeopleNumber)
:Circlist<Type>(headValue),Number(value_Number),StartNumber(value_StartNumber),PeopleNumber(value_PeopleNumber){
}
void initalList();
bool Run();//affair start to work;
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -