?? p82_2.cpp
字號:
#include <stdio.h> #include <iostream.h> enum Boolean { False, True }; template <class Type> class CircList; template <class Type> class CircListNode { friend class CircList<Type>; public: CircListNode ( Type d=0, CircListNode<Type> *next=NULL ) : data (d), link (next) { } private: Type data; CircListNode<Type> *link; }; template <class Type> class CircList { public: CircList (); CircList ( Type value ); //構造函數(shù) ~CircList ( ); //析構函數(shù) int Length ( ) const; //計算循環(huán)鏈表長度 Boolean IsEmpty ( ) { return first->link == first; } //判表空否 Boolean Find ( const Type & value ); //在循環(huán)鏈表中尋找其值等于value的結點 Type getData ( ) { return current->data; } //返回當前結點中存放的值 Type getNextData () ; void Firster ( ) { current = first; } //將當前指針置于頭結點 void First ( ); //將當前指針指向鏈表的第一個結點 void Next ( ); //將當前指針指到當前結點的后繼結點 void Prior ( ); //將當前指針指到當前結點的前驅(qū)結點 void Insert ( const Type & value ); //插入新結點 void RemoveNext ( ); void Josephus ( int n, int m ); //刪除當前結點 private: CircListNode<Type> *first, *current, *last; //頭指針, 當前指針, 尾指針 }; template <class Type> void CircList <Type> :: CircList () { current = last = first = new CircListNode<Type> (); first->link = first; } template <class Type> void CircList <Type> :: ~CircList () { CircListNode<Type> *q; while ( first->link != first ) { q = first->link; first->link = q->link; delete q; } delete first; current = first = last = NULL; } template <class Type> void CircList <Type> :: Next () { if ( current->link == first ) current = first; current = current->link; } template <class Type> Type CircList <Type> :: getNextData() { if ( current->link == first ) return first->link->data; else return current->link->data; } template <class Type> void CircList <Type> :: RemoveNext () { CircListNode<Type> *p = current->link; if ( p == last ) last = current; if ( p != first ) current->link = p->link; else { p = first->link; first->link = p->link; } delete p; } template <class Type> void CircList <Type> :: Insert (const Type & value) { CircListNode<Type> *p = new CircListNode<Type> ( value, first ); last = last->link = p; }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -