C 實現迴圈鍊錶

2021-05-27 07:15:38 字數 1847 閱讀 1662

vs2005執行通過,如有問題,請各位大牛指正。謝謝

注意:迴圈鍊錶含有頭結點

#include using namespace std;

templatestruct node

;templateclass circlist

;templatecirclist::circlist() //初始化時,只有乙個頭結點,有head指向

templatecirclist::circlist(const circlist&otherlist)

if (otherlistcurrent->next==otherlist.head)

}}templateconst circlist& circlist::operator=(const circlist&otherlist)//賦值函式

while(otherlistcurrent!=otherlist.head)

} return *this;//為了連續賦值

}templatecirclist::~circlist()

templatevoid circlist::createlistforward()//頭插法

}templatevoid circlist::createbackward()//尾插法

}templatevoid circlist::initlist() //只剩下頭結點,和指標設定

templatebool circlist::isemptylist()

else }

templatevoid circlist::printlist() }

templateint circlist::length()

templatevoid circlist::destorylist()//銷毀包括頭結點

delete temp;

len=0; }}

templatevoid circlist::getfirstdata(type& firstitem)

else

if (current!=head)

templatevoid circlist::insertlast(const type newitem)

//此時current指向結點的尾部,就是應該插入的位置

newnode->next = current->next;

current->next = newnode;

len++;

}templatevoid circlist::insertbefore(const int pos,const type newitem)

else

newnode->next = current->next;

current->next = newnode;

} len++;

}templatevoid circlist::insertafter(const int pos,const type newitem)

newnode->next = current->next;

current->next = newnode;

len++;

}templatevoid circlist::deletenode(const type deleteitem)

if (current==null)

temp = current->next;

current->next = temp->next;

deleteitem = temp->data;

delete temp;

len--;

}templatevoid circlist::reverse() }}

void main()

迴圈鍊錶 C實現

沒有頭結點 define crt secure no warnings include include typedef struct list list void creat list list p 如果鍊錶為空,則建立乙個鍊錶,指標域指向自己,否則尋找尾節點,將 else 輸入的鍊錶不是空的,尋找...

C 實現雙向迴圈鍊錶

雙向迴圈鍊錶 除錯正常,所有功能均測試 節點類 template class listnode listnode type d,listnode n nullptr,listnode p nullptr data d next n prev p void setdata type d 雙向迴圈鍊錶 ...

C實現迴圈鍊錶及雙向鍊錶

在雙向鍊錶中,結點除含有資料域外,還有兩個鏈域,乙個儲存直接後繼結點位址,一般稱之為右鏈域 乙個儲存直接前驅結點位址,一般稱之為左鏈域。鍊錶的c語言實現之迴圈鍊錶及雙向鍊錶 一 迴圈鍊錶 迴圈鍊錶是與單鏈表一樣,是一種鏈式的儲存結構,所不同的是,迴圈鍊錶的最後乙個結點的指標是指向該迴圈鍊錶的第乙個結...