字串鍊錶設計

2021-06-22 14:32:54 字數 2217 閱讀 5435

標頭檔案

#ifndef _link_h_

#define _link_h_

typedef struct stringnode

stringnode;

/*1.向鍊錶尾部插入乙個元素*/

int tailinsertnode(stringnode **pnode, char *ptaildata);

/*2.遍歷*/

void printlist(stringnode *phead);

/*3.清空*/

void deletelist(stringnode **phead);

/*4.返回鍊錶長度*/

int sizelist(stringnode *phead);

/*5.刪除指定鍊錶節點*/

int deleteonenode(stringnode **phead, char *strdel);

/*6.是否空鍊錶*/

bool isemptylist(stringnode *phead);

/*7.查詢指定字串*/

bool i***istinlist(stringnode *phead, char *strfind);

#endif

原始檔

#include #include #include #include "link.h"

/**使用範例

int main(void)

;    strncpy(str, "hello world \n", 6);

tailinsertnode(&pfilenode, str);

tailinsertnode(&pfilenode, "asdj asda");

printlist(pfilenode);

if (!isemptylist(pfilenode))

deletelist(&pfilenode);

printlist(pfilenode);

}getchar();

return 0;}*/

/*1.在尾部插入新節點*/

int tailinsertnode(stringnode **pnode, char *ptaildata)

memset(pinsert, 0, sizeof(stringnode));

pinsert->nlen = strlen(ptaildata)+1;

pinsert->pdata = (char *)malloc(pinsert->nlen);

if (null == pinsert->pdata)

strcpy(pinsert->pdata, ptaildata);

pinsert->next = null;

/*如果頭結點沒有資料,則新節點作為走節點*/

if (phead == null)

else

ptmp->next = pinsert;//將鍊錶末尾節點的下一結點指向新新增的節點

}*pnode = phead; 

return 0;

}/*2.遍歷*/

void printlist(stringnode *phead)

}/*3.清空*/

void deletelist(stringnode **phead)

*phead = null;

}/*4.返回鍊錶長度*/

int sizelist(stringnode *phead)

return nsize;

}/*5.刪除指定鍊錶節點*/

int deleteonenode(stringnode **phead, char *strdel)

else

}if (ptmp->next == null)

pback = ptmp;

ptmp = ptmp->next;

if (strcmp(ptmp->pdata, strdel) == 0)

}return 0;

}/*6.是否空鍊錶*/

bool isemptylist(stringnode *phead)

return false;

}bool i***istinlist(stringnode *phead, char *strfind)

phead = phead->next;

}return false;

}

字串比較 鍊錶實現

用鍊錶實現兩個字串的比較,相同則提示the same 並把他們列印出來 只用列印乙個就行了 不同提示not the same,然後把兩個不同的字串分別列印出來。源 如下 vc6.0編譯通過 include include struct string int string cmp struct str...

(字串)LC相交鍊錶

先遍歷一遍鍊錶a,將存在的節點存入雜湊表中,再遍歷鍊錶b,第乙個遇到已經存在的節點,即相交點 public listnode getintersectionnode listnode heada,listnode headb while b null return null 比較巧妙的方法,a和b的...

DS 鍊錶 字串演算法設計

第五周上機課開始限時模式 規定了鍊錶用struct 之前沒有接觸過struct的函式所以摸索了好久 不過好歹是在課上寫出來了第一題 第二題回來思考了一下也寫出來了,應該是o n 複雜度 刪除鍊錶中的重複元素並排序 給定乙個排序鍊錶,刪除所有含有重複數字的節點,只保留原始鍊錶中 沒有重複出現 的數字。...