今天c語言的複習告一段落,雖然不是特別完美,但還是要記錄一下單鏈表的基本操作,上**:
#define _crt_secure_no_warnings
#include "link.h"
void head_insert(stu **head)
memset(new_node, 0, sizeof(stu))
;//清空結構體
//2.給節點賦值
scanf(
"%d %s %f",&new_node->num,new_node->name,&new_node->score)
; //3.對頭(節點)進行判斷
stu *pf=*head;
*head = new_node;//指標賦值
pf == null?(new_node->next = null):(new_node->next = pf);}
void tail_insert(stu **head)
memset(new_node, 0, sizeof(stu))
; scanf(
"%d %s %f", &new_node->num, new_node->name, &new_node->score)
; stu *pf = *head;
if(pf==null)
*head = new_node;
else
pf->next= new_node;}}
void sort_insert(stu **head)
scanf(
"%d %s %f", &new_node->num, new_node->name, &new_node->score)
; stu *pf = *head;
if(pf == null)
*head = new_node;
else
else}if
(pf == *head )
else
if(pf !=null)
else}}
void search_link(stu **head)
; printf(
"請輸入你想查詢學生的姓名:");
scanf(
"%s", temp1)
; stu* pf = *head;
if(pf == null)
else
pf = pf->next;}if
(temp == 0)}}
void delete_link(stu **head)
else
else
if(pf ->next!= null)
else
temp = 1;
} te*** = pf;
pf = pf->next;}if
(temp == 0)printf(
"沒有找到學號%d相關的節點資訊\n", temp1)
;else printf(
"刪除學號%d相關的節點資訊成功!!!\n",temp1);if
(temp2 != null)}}
void free_link(stu **head)
else
//釋放時必須傳入的頭結點操作
} printf(
"link釋放成功\n");
}}void print_link(stu **head)
while(pf != null)
}
執行結果:
單鏈表基本操作
include include include include includeusing namespace std typedef struct node node,plinklist plinklist createfromhead node pstnode node malloc sizeof...
單鏈表基本操作
單鏈表的初始化,建立,插入,查詢,刪除。author wang yong date 2010.8.19 include include typedef int elemtype 定義結點型別 typedef struct node node,linkedlist 單鏈表的初始化 linkedlist...
單鏈表基本操作
include using namespace std define namelenth 20 define ok 0 define error 1 typedef struct flagnode node 生成結點 inline node newnode 銷毀化煉表 void destroylin...