單鏈表的建立測長列印

2021-08-21 13:07:38 字數 1731 閱讀 3794

#define _crt_secure_no_warnings

#include

#include

#include

#include

using namespace std;

typedef struct student

node;

node*creat()

else cycle = 0;

}head = head->next;

p->next = null;

printf("\n yyy  %d", head->data);

return (head);

}//單鏈表測長

int length(node*head)

return (n);

}//單鏈表列印

void print(node*head)

}單鏈表的刪除節點:

status listdelete(linklist *l, int i, elemtype *e)

if (!(p->next) || j > i)

return error;

}p->next = q->next;

*e = q->data;

free(q);

//單鏈表的插入

node*insert(node*head, int num)

if (p0->data <= p1->data)

else

}else

//程式設計實現單鏈表的排序

node *sort(node*head)

p = p->next;}}

return head

}//單鏈表的逆置

node*reverse(node*head)

head->next = null;

head = p1;

return head;

}int main()

//鍊錶環的判斷及入口結點的查詢

node*findloopport(node*head)

slow = fast = head;

//先判斷是否存在環

while (fast != null&&fast->next != null)

if (fast != slow)

return null;

fast = head;

while (fast != slow)

return fast;

}

//判斷兩個鍊錶是否相交

bool isintersect(node*h1, node h2)

while (h2->next != null)

if (h1 == h2)

return true;;

else

return false;

}

//鍊錶有環,如何判斷相交

bool isinsertsectwithloop(node*h1,node*h2)

return true;

}

//兩個鍊錶相交的第乙個公共節點

node*findinsetersectnode(node*h1, node*h2)

else

while (h1 != null)

return null;

}

雙鏈表的建立 測長 列印 刪除 插入

include using namespace std struct node int n 0 節點個數 鍊錶的建立,尾插法 struct node create struct node head q p n p new node cin p data p pre null p next null ...

單鏈表的建立 測長和列印

面試寶典中第13章,實現單鏈表的建立測長和列印 include include include includeusing namespace std 單鏈表結構體 typedef struct student node 建立單鏈表 node create else head head next p ...

實現乙個單鏈表的建立 測長 列印,插入,排序,逆置

taotao definition created by taotao man on 2015 9 30 brief 實現乙個單鏈表的建立 測長 列印,插入,排序,逆置 修改記錄 date add seta set geta include stdio.h include include conio...