//c++ stl中的鍊錶
#include
"list.h"
//我做的鍊錶
using
namespace std;
intmain()
cout <<
"測試一下迴圈:"
<< endl;
listiterator<
int>
iter
(intlist)
; cout <<
*iter.
first()
<< endl;
cout <<
*iter.
next()
<< endl;
cout <<
*iter.
next()
<< endl;
cout <<
*iter.
next()
<< endl;
cout <<
*iter.
next()
<< endl;
cout <<
*iter.
next()
<< endl;
cout <<
*iter.
next()
<< endl;
return0;
}list.h
#ifndef list_h
#define list_h
#include
//迴圈鍊錶
template
<
class
type
>
class
list
;template
<
class
type
>
class
listiterator
;template
<
class
type
>
class
listnode};
template
<
class
type
>
listnode
::listnode
(type element)
template
<
class
type
>
class
list
;void
insert
(type)
;void
delete
(type)
;private
: listnode
*first;};
template
<
class
type
>
void list
::insert
(type k)
template
<
class
type
>
void list
::delete
(type k)
if(current != first)
}template
<
class
type
>
class
listiterator
bool
notnull()
;bool
nextnotnull()
; type*
first()
; type*
next()
;private
:const list
&list;
listnode
* current;};
template
<
class
type
>
type* listiterator
::first()
template
<
class
type
>
type* listiterator
::next()
template
<
class
type
>
bool listiterator
::notnull()
template
<
class
type
>
bool listiterator
::nextnotnull()
#endif
引用:迴圈鍊錶(約瑟夫環)的建立及c語言實現
資料結構之迴圈鍊錶
迴圈鍊錶是資料結構中煉表的一種形式。相對於單向鍊錶,將單向鍊錶的尾結點的指標域指向該單向鍊錶的頭結點,就構成了迴圈鍊錶。可以這麼理解,單向鍊錶就是一張單程火車票,比如你要從北京坐火車去上海,路上經過濟南 南京,此時北京 濟南 南京 上海就構成了單向鍊錶的四個結點,如下圖所示。但是,單向鍊錶是有去無回...
資料結構之迴圈鍊錶
前面學習了鏈式結構鍊錶,鏈式結構鍊錶也有使用的侷限性。比如說我們經常碰到的迴圈關係,最經典的當然是約瑟夫問題了,那麼我們怎麼去解決約瑟夫問題呢?相信你看完本文章就會了,好了言歸正傳,我們生活中經常會遇到迴圈問題,例如,一年的12個月,春夏秋冬交替,這些迴圈關係怎麼在我們的程式體現出來,少廢話,上 第...
資料結構之迴圈鍊錶
首先先了解如何判斷單鏈表中是否有環 環的定義 鍊錶中的尾節點指向了鍊錶中的某個節點。方法一 使用p q兩個指標,p一直往前走,q每次從頭往前走,當p等於q但是p q移動的步數不相等的時候,存在環。方法二 使用p q兩個指標,p每次往前走一步,q每次往前走兩步,當存在p q的時候,存在環。迴圈鍊錶,只...