count記錄的是單鏈表的總長
count1記錄的是公升序的結點的個數
count2記錄的是降序的結點的個數
如果count1或者count2等於count,那麼就說明該序列是公升序或者降序的。
稍加改進可以在準確判斷是公升序還是降序還是無序
(個人認為鍊錶中只有乙個結點或者沒有結點都是有序的)
#include #include typedef struct link_node
n;n *init()
n *creat(n *head)
else
scanf("%d",&x);
} return head;
}void display(n *head)
while(p)
printf("\n");
}int length(n *head)
return count;
}int judge(n *head)
if(head && !head->next)
while(p->next)
if(p->info >=p->next->info)
p=p->next;
} //count是鍊錶的總長度
count=length(head);
printf("count1 = %d\ncount2 = %d\ncount = %d\n",count1,count2,count);
if(count == count1 || count == count2)
else }
int main ()
else
return 0;
}
資料結構 帶頭結點的單鏈表
比較坑爹的基礎啊,大把時間浪費在建構函式上,建構函式 出生決定命運!自己解決的bug,感覺還不錯。其實程式的核心是演算法,演算法建立在資料結構的基礎之上。大部分的程式設計師現在學的基本都是規則,而不是創造。但掌握了規則,也能創造很多財富。重新鞏固我弱爆了的資料結構,沒敲完資料結構的程式設計師不是好領...
資料結構 單鏈表(帶頭結點)
單鏈表是一種鏈式訪問的資料結構,用一組位址任意的儲存單元存放線性表中的資料元素。鍊錶中的資料是以結點來表示的,每個結點的構成 元素 資料元素的映象 指標 指示後繼元素儲存位置 元素就是儲存資料的儲存單元,指標就是連線每個結點的位址資料。簡單講就是邏輯相鄰,物理不相鄰 帶頭結點 list.h prag...
資料結構中(單鏈表)
list.h lish.h ifndef list h define list h typedef int elementtype struct node typedef struct node ptrtonode typedef ptrtonode list typedef ptrtonode p...