資料結構 C 版 鍊錶

2021-04-13 12:59:51 字數 3331 閱讀 5786

大家如果有什麼問題,可以給我發email:[email protected]

下面是c#版鍊錶的實現過程

分為兩個類: 1.

csarraylistnode

類,用於表示乙個結點 2.

csarraylist,

用於表示鍊錶本身

下面是這兩個類的檢視

大家可以根據檢視得到這兩個類的基本結構 ,**中有詳細的注釋.

大家也可以從下

如果有什麼問題可以傳送以下email到我們的工作室,我們會在最短的時間內給您解答

[email protected]

[email protected]

using

system;

using

system.collections.generic;

using

system.text;

using

system.collections;

namespace鍊錶

set }

private

csarraylistnode nextnode;

////// 該結結點的下乙個結點的引用

///public

csarraylistnode nextnode

set }

}///

/// 用於表示鍊錶

///public

class

csarraylist }

//////

將物件新增到 csarraylist 的結尾處。

//////

要新增到 csarraylist 的末尾處的 object。該值可以為 空引用.

public

void add(object item)

// 非第一次加入元素

else

tmpnode = tmpnode.nextnode; }

} //

鍊錶長度增加1

this.count++; }

////// 從 csarraylist 中移除所有元素。

///public

void clear()

//////

確定某元素是否在 csarraylist 中。

//////

要在 arraylist 中查詢的 object。該值可以為 空引用

/// 如果在 csarraylist 中找到 item,則為 true;否則為 false。

public

bool contains(object item)

if (tmpnode .element .equals (item))

tmpnode = tmpnode.nextnode; }

}///

/// 搜尋指定的 object,並返回整個 arraylist 中第乙個匹配項的從零開始的索引。

//////

要在 arraylist 中查詢的 object。

/// 如果在整個 arraylist 中找到 value 的第乙個匹配項,則為該項的從零開始的索引;否則為 -1。

public

int indexof(object value)

// 否則返回索引號

if (tmpnode.element.equals(value ))

tmpnode = tmpnode.nextnode;

index++; }

}///

/// 將元素插入 arraylist 的指定索引處。

//////

從零開始的索引,應在該位置插入 value。

/// 要插入的 object。

public

void insert(int index, object value)

// 如果索引號是0,則直接將該值插入第乙個結點

if (index == 0)

csarraylistnode tmpnode = this.firstnode;

int index1 =0;

while (true)

// 插入新值,這裡要注意結點是如何交換的

//c#

的類名就是引用,這一點類似於c++中的指標

if (index ==(index1+1))

tmpnode = tmpnode.nextnode;

index1++; }

}///

/// 從 arraylist 中移除特定物件的第乙個匹配項。

//////

要從 arraylist 移除的 object。

public

void remove(object value)

int index = 0;

csarraylistnode tmpnode = this.firstnode;

while (true)

if (tmpnode .nextnode .element .equals (value ))

tmpnode = tmpnode.nextnode;

index++; }

}///

/// 移除 arraylist 的指定索引處的元素。

//////

要移除的元素的從零開始的索引。

public

void removeat(int index)

if (index==0)

int index1 = 0;

csarraylistnode tmpnode = this.firstnode;

while (true)

if (index ==(index1 +1))

tmpnode = tmpnode.nextnode;

index1++; }

}public

object

this[int index]

csarraylistnode tmpnode = this.firstnode;

for (int i = 0; i < index; i++)

return tmpnode.element; }

setcsarraylistnode tmpnode = this.firstnode;

for (int i = 0; i < index; i++)

tmpnode.element=value ; }

} }}

資料結構 C 版 鍊錶

原文 http blog.csdn.net warensoft archive 2007 10 16 1827279.aspx 下面是c 版鍊錶的實現過程 分為兩個類 1.csarraylistnode 類,用於表示乙個結點 2.csarraylist,用於表示鍊錶本身 下面是這兩個類的檢視 大家可...

資料結構 鍊錶 JAVA版

和c 並沒有差別不大,主要是指標改為了引用變數,其他的鏈式結構基本可以參照這個 至於樹的話注意下遞迴就大致可以了 package com.sun.study.test class link public void display class linklist public boolean isemp...

資料結構 鍊錶(C語言版)

程式 include include include define error 0 define ok 1 define true 1 define false 0 define overflow 2 typedef int elemtype 定義鍊錶元素的型別 typedef int status...