資料結構和演算法 Day 17

2021-08-07 18:24:29 字數 1319 閱讀 4803

將單鏈表中終端節點的指標端由空指標改為指向頭節點,就使整個單鏈表形成乙個環,這種頭尾相接的單鏈表稱為單迴圈列表,簡稱迴圈列表。

迴圈列表的主要差異就在於迴圈的判斷空列表的條件上,原來判斷head->next是否為null,現在則是head->next是否等於head

終端節點用尾指標rear指示,則查詢終端結點的結果是o(1),而開始結點是rear->naxt->naxt,當然也是o(1)

/*鍊錶結構的定義*/

typedef struct clinklist

node;

/*初始化迴圈列表*/

void ds_init(node **pnode)

else

} }

/*插入結點*/

/*引數:鍊錶的第乙個節點,插入的位置*/

void ds_insert(node **pnode, int i)

temp->data = item;

/*尋找最後乙個結點*/

for(target = (*pnode); target->naxt != (*pnode); target = target->next) ;

temp->next = (*pnode);

target->next = temp;

*pnode = temp;

} else

temp = (node*) malloc(sizeof(struct clinklist));

if( !temp )

temp->data = item;

p = target->next;

target->next = temp;

temp->next = p;

}}

/*刪除結點*/

void ds_delete(node **pnode, int i)

else

temp = target->next;

target->next = temp->next;

free(temp);

}}

/*返回結點所在位置*/

int ds_search(node *pnode, int elem)

if( target->next == pnode ) /*表中不存在該元素*/

return 0;

else

return i;

}

資料結構 day 17

並查集 1.將兩個集合合併 2.詢問兩個元素是否在乙個集合當中。belong x a if belongp x belong y 近乎o 1 基本原理 每個集合用一棵樹來表示,樹根的編號就是整個集合的編號。每個節點儲存它的父節點,p x 表示x的父節點。問題1 如何判斷樹根 if p x x 問題2...

每日演算法 day 17

那些你早出晚歸付出的刻苦努力,你不想訓練,當你覺的太累了但還是要咬牙堅持的時候,那就是在追逐夢想,不要在意終點有什麼,要享受路途的過程,或許你不能成就夢想,但一定會有更偉大的事情隨之而來。mamba out 2020.2.29 簡單模擬 include include include include...

Day 17 網路和爬蟲

day 17 網路協議 物件為客戶端和伺服器 網路中部署了各種各樣的伺服器,客戶端通過url 請求位址 找到指定的伺服器 url 不同的協議代表著不同的資源查詢方式和傳輸方式,其中 存放資源的主機 伺服器 的ip位址 一般為網域名稱,網域名稱就是對ip位址進行包裝 資源在主機 伺服器 中的具體位置 ...