#include #include #include using namespace std;
templatestruct dblnode
dblnode(t d, dblnode*left = null, dblnode* right = null)
:data(d)
,llink(left)
,rlink(right)
{}};
templateclass dbllink
dbllink(const t& val)
~dbllink()
void makeempty()
dblnode*p = null;
while(first->rlink != first)
}int length() const//計算雙鏈表的長度
return count;
} bool isempty()//判空
return false; }
dblnode*search(const t& x)
//在鍊錶中延後繼方向尋找等於給定值x的結點
dblnode* p = first->rlink;
while(p != first)
p = p->rlink;
} return p;
} dblnode*locate(int i, int d)
//在鍊錶中定位序號為i的結點,d=0按前驅方向,反之按後繼方向
if(d != 0)
return current;
} else
return current;
} }bool insert(int i, const t& x, int d)
//在第i個結點之後插入乙個包含有值x的新結點,d=0按前驅方向,反之按後繼方向
dblnode* s = new dblnode(x);
s->rlink = current->rlink;
s->rlink->llink = s;
current->rlink = s;
s->llink = current;
return true;
} bool remove(int i, t& x, int d)
//刪除第i個結點,x返回其值,d=0按前驅方向,反之按後繼方向
dblnode* current = locate(i-1,d);
if(current == null&& current->rlink == first)
dblnode* del = current->rlink;
current->rlink = del->rlink;
del->rlink->llink = current;
x = del->data;
delete del;
return true;
} void pushback(const t& x)
dblnode*s = new dblnode(x);
p->rlink = s;
s->llink = p;
s->rlink = first;
first->llink = s;
} void input() //輸入 }
void output() //輸出
cout << "first" << endl;
}private:
dblnode*first;
};
C 迴圈鍊錶(殷人昆版)
include include include using namespace std templatestruct circlistnode circlistnode t d,circlistnode n null data d next n templateclass circlist circ...
雙向鍊錶和雙向迴圈鍊錶
和單向鍊錶相比,多了乙個前驅結點。如果他為空,那麼next和prior都指向自己。而對於雙迴圈鍊錶,只需要最後乙個元素的next指向head next,head next的prior指向最後乙個節點即可。新節點s插入鍊錶,s next給p結點,s prior給p prior,然後,p prior n...
迴圈鍊錶,雙向鍊錶
迴圈鍊錶 迴圈鍊錶與順序鍊錶之間的區別 迴圈鍊錶最後乙個資料的next指標域不為空,而是指向頭結點,其他基本操作大體相同,只是在判斷表結束的條件變為判斷節點的引用域是否為頭引用 雙向鍊錶 author neosong date oct 10,2017 4 43 01 pm program of in...