劍指offer 鍊錶

2021-10-06 11:45:32 字數 1563 閱讀 5230

題目描述:

思路分析:

**實現:

#include#includetypedef struct nodenode;

node* creatlinklist(int n)

return head;

}void reversedisplay(node *h)

printf("%d ",h->data);

}int main()

return 0;

}

題目描述:

思路分析:

定義兩個快慢指標,如果存在環,則快指標必定會追上慢指標,否則無環

**實現:

#include#includetypedef struct nodenode;

node* createlinklist(int n)

tail->next = head->next->next; //loop

return head;

}node* loopenternode(node *fast,node *phead)

return fast;

}node* i***itloop(node *head)

} return null;

}int main(void)

return 0;

}

題目描述:

思路分析:

第一步遍歷鍊錶,對每個節點做記錄;

第二步再次遍歷鍊錶,刪除記錄值大於1次的節點

**實現:

#include#include#define n 10000

typedef struct nodenode;

int record[n] = ;

node* createlinklist(int n)

return head;

}void displaylist(node *head)

printf("\n");

}void delrepeatnode(node *head)

h = head;

while(h->next != null)

h = h->next;

} displaylist(head);

}int main(void)

*/ scanf("%d",&num);

node *head = createlinklist(num);

printf("enter:");

displaylist(head);

printf("after:");

delrepeatnode(head);

return 0;

}

劍指offer 鍊錶

單向鍊錶的結構定義 typedef int datatype struct listnode 問題1 往鍊錶的末尾新增乙個結點 給定頭結點,往末尾插入乙個結點 void insertnode listnode head,datatype key listnode p head while p nex...

劍指offer 鍊錶

鍊錶 鍊錶是一種動態資料結構 struct listnode 往鍊錶的末尾新增乙個節點的c 程式如下 void addtotail listnode phead,int value 注意第乙個引數phead是乙個指向指標的指標。當我們往乙個空鍊錶插入乙個結點時,else pnode m pnext ...

劍指offer 鍊錶

在乙個排序的鍊錶中,存在重複的結點,請刪除該鍊錶中重複的結點,重複的結點不保留,返回煉表頭指標。思路1 遞迴版 class solution 找到當前節點與下乙個節點不重複的點,從不重複的點開始遞迴 return deleteduplication phead next else 思路2 非遞迴版 ...