1. 程式人生 > >單鏈表的建立,刪除,插入,顯示,排序

單鏈表的建立,刪除,插入,顯示,排序

{

    
struct student *head, *stu;
    
int num;
    
    printf(
"input records: ");
    head 
= creat();
    show(head);
    
    printf(
"  input the deleted number:");
    scanf(
"%d"&num);
    
while (num !=0)
    
{
        head 
= del(head, num);
        show(head);
        printf(
"  input the deleted number:
");
        scanf(
"%d"&num);
    }

    
    printf(
"  input the inserted record:");
    stu 
= (struct student *)malloc(sizeof(struct student));
    scanf(
"%d, %d"&stu->infor.num, &stu->infor.score);
    
while (stu->infor.num !=0)
    
{
        head 
= insert(head, stu);
        show(head);
        printf(
"  input the inserted record:");
        stu 
= (struct student *)malloc(sizeof(struct student));//重新分配一次記憶體,以免覆蓋掉上一次的節點
        scanf("%d, %d"&stu->infor.num, &stu->infor.score);
    }

    
    head 
= sort(head);
    show(head);
    
    
return0
}

相關推薦

C++寫的帶有頭結點單鏈建立插入刪除顯示

#include<iostream> usingnamespacestd; structlink { chardata; structlink*next; }; link*head,*tail;//建立頭指標和尾指標 intcreat(); /******

單鏈建立插入刪除

學程式設計的小菜鳥一枚,希望未來好好學習天天向上~ 歡迎各位大神前來指正~ 放上資料結構的初次作業^_^(其實。。只做了一部分(°-°)) 以下函式在VC6.0的環境中執行通過 //定義結構體 typedef struct link { int

單鏈建立逆序刪除

#include<stdio.h> #include<string.h> #include<stdlib.h> typedef struct link{

C 將一個單鏈拆成3個迴圈連結串列其中一個是純數字一個純字母一個其他字元

前面相關操作在這呢,這個函式依託於此 //結構體 typedef struct Node { ElementType data; struct Node * next; } LNode, * LinkNode; //將一個單鏈表拆成3個迴圈連結串列,其中一個是純數字

判斷單鏈是否帶環?若帶環求環的長度?求環的入口點?

判斷單鏈表是否帶環?若帶環,求環的長度?求環的入口點? 這道題有三問,是否帶環?環的長度?環的入口點? 1.單鏈表是否帶環? 思路分析:怎麼樣才算帶環呢?我們細想,如果一個單鏈錶帶環的話,那麼它怎麼走都走不出來的,而如果不帶環的話,那麼一定會走到NULL的。

判斷單鏈是否帶環?若帶環求環的長度,求環的入口點

判斷是否帶環,若帶環返回相遇點,否則返回空 pNode IsCircle(pList plist) { pNode pFast = plist; pNode pSlow = plist; while (pFast && pFast->next)

【MySQL 】要點——刪除插入“行”“列”主鍵設定

*寫在前面提醒自己:DOS命令寫SQL寫完最後一個語句要加分號“;”。 一、刪除 delete:刪除表中的 行 ,如 delete from 表名 where 欄位名=值; drop:刪除索引、表或者資料庫,如 drop table 表名; truncate:刪

java實現---判斷單鏈是否帶環?若帶環求環的長度?求環的入口點?

判斷 單鏈表是否帶環 若帶環,求環的長度 求環的入口點 單鏈表是否帶環 判斷一個連結串列是否帶環 我們可以定義兩個快慢節點,快的一次走兩步,

Java實現堆的封裝進行插入調整刪除堆頂以完成堆排序例項

簡介 堆對於排序演算法是一個比較常用的資料結構,下面我就使用Java語言來實現這一演算法 首先,我們需要知道堆的資料結構的形式,其實就是一個特殊的二叉樹。但是這個二叉樹有一定的特點,除了是完全二叉樹以外,對於最大堆而言,堆頂元素的值是最大的,而且對於

單鏈應用舉例(單鏈A和單鏈B的元素都是非遞減排列利用單鏈的基本運算將它們合併成一個單鏈C要求C也是非遞減序列)

標頭檔案:函式的定義 #include <stdio.h> #include <malloc.h> #include <stdlib.h> #include <string.h> typedef int ElemType; t

給定單鏈L:L0→L1→...→Ln-1→Ln 重新排序:L0→Ln→L1→Ln-1→L2→Ln-2→...

本題源自leetcode  143 ---------------------------------------------------------------------------- 思路1:用快慢指標找到中節點,然後反轉後半部分連結串列。然後倆個連結串列交叉插入 程

C語言:單鏈實現(二) 就地逆置就地歸併

#include<iostream> #include<stdio.h> #include<math.h> #define LEN sizeof(struct Nodelist) using namespace std; typedef

C++ 單鏈建立插入刪除

#include <iostream> #include <stdio.h> #include <string> #include <conio.h> /** * cstdio是將stdio.h的內容用C++標頭檔案的形式表

單鏈進行求平均數(去掉最大數最小數)

package DataStructureTestmain; import DataStructureTestSinglyLinkedList.Node; import DataStructure

連結串列初解(一)——單鏈建立刪除插入、測長、排序、逆置

由於考試需要,複習一下單鏈表的各種常見操作,直接上程式碼+註釋,需要的可以參考下哈~ Code: #include<iostream> using namespace std; typedef struct student { int data; str

LeetCode83 給定一個排序連結串列刪除所有重複的元素使得每個元素只出現一次。

給定一個排序連結串列,刪除所有重複的元素,使得每個元素只出現一次。 /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode

一個有序的陣列中刪除重複出現的元素輸出不再重複出現的元素個數

輸入:1,1,2,2,2,3,3,4,4,5,5,5,5 輸出:5 public static int removeDuplicates1(int[] nums) { if (nums == null || nums.length < 1) ret

Linux Vi 刪除全部內容刪除某行到結尾刪除某段內容 的方法

1.開啟檔案 vi filename 2.轉到檔案結尾 G 或轉到第9行 9G 3.刪除所有內容(先用G轉到檔案尾)(%$$#^71267*&%2)我型我塑www.5x54.com ,使用: :1,.d 或者刪除第9行到第200行的內容(先用200G轉到第200

iOS NSUserDefaults setObject forKey,本地化儲存刪除字典中的null空值本地化的時候如果value為空值所引起的崩潰

刪除字典中的null 我們在處理伺服器傳過來的資料過程中,如果資料中出現null,我們是沒法進行本地持久化處理的。在使用NSUserDaults儲存本地時,如果其中一個欄位的value為NULL值,就會出現崩潰。 null產生原因 null是後臺在處理資料的時候,如

C語言實現單鏈節點的刪除(帶頭結點)

data art pos grand urn ria tps move sni 我在之前一篇博客《C語言實現單鏈表節點的刪除(不帶頭結點)》中具體實現了怎樣在一個不帶頭結點的單鏈表的刪除一個節點,在這一篇博客中我改成了帶頭結點的單鏈表。代碼演示樣例上傳至 h