【正文】
替對應的空函數(shù)后運行程序。 head 頭結點 q num next 使指針變量 q也指向該頭結點。 p = (LST *) malloc ( sizeof (LST) )。 p ( 3)編寫 mycreat( )函數(shù),并用此函數(shù)代替對應的空函數(shù)后運行程序。 head 頭結點 q num next 結點 1 num next 使 q指向新鏈表的最后一個結點。 101 p ( 3)編寫 mycreat( )函數(shù),并用此函數(shù)代替對應的空函數(shù)后運行程序。 101 p q p = (LST *) malloc ( sizeof (LST) )。 101 q p ( 3)編寫 mycreat( )函數(shù),并用此函數(shù)代替對應的空函數(shù)后運行程序。 head 頭結點 num next 結點 1 num next 新結點 num next 使 q指向新鏈表的最后一個結點。 101 q 103 p ( 3)編寫 mycreat( )函數(shù),并用此函數(shù)代替對應的空函數(shù)后運行程序。 返回鏈表頭結點的地址 。 head = (LST*)malloc ( sizeof (LST) )。 scanf (%d, amp。 p num = m。m )。 head 頭結點 結點 1 結點 2 尾結點 \0 101 103 105 使指針 p指向鏈表中結點 1 。 101 head 頭結點 結點 1 結點 2 尾結點 \0 101 103 105 移動 p,即使 p指向下一個結點。 p printf (%5d, p num )。 head 頭結點 結點 1 結點 2 尾結點 \0 101 103 105 輸出 p所指結點的 num成員值。 不存在 , 所以 p=NULL p = p next。 else do { printf ( %5d, p num )。 } ( 5)編寫 myinsert ( )函數(shù),并用此函數(shù)代替對應的空函數(shù)后運行程序。 s num = m。 head 頭結點 結點 1 尾結點 結點 2 新結點 s 101 103 105 \0 104 q p 判斷是否找到插入點。 p head 頭結點 結點 1 尾結點 結點 2 新結點 s 101 103 105 \0 104 q q、 p都移到下一個結點。 if ( p num = m ) p 結點 2 head 頭結點 結點 1 尾結點 結點 2 新結點 s 101 103 105 \0 104 q p q、 p都移到下一個結點。 q = q next。 s next = p。 s num = m。 p = p next。 } ( 6)編寫 mydelete ( )函數(shù),并用此函數(shù)代替對應的空函數(shù)后運行程序。 head 頭結點 結點 1 尾結點 結點 2 101 103 105 \0 判斷是否找到需刪結點。 head 頭結點 結點 1 尾結點 結點 2 p 101 103 105 \0 q、 p都移到下一個結點。 if ( m != p num ) p q head 頭結點 結點 1 尾結點 結點 2 101 103 105 \0 刪除結點 q next = p next。 p = head next。 if ( p == NULL ) return 0。 } 實例的部分程序 P268 【 實例 12】 用結構體類型數(shù)據(jù),編寫實現(xiàn)電子通訊錄功能的程序。 free (p)。 p = pnext。 int mydelete ( LST *head, int m ) { LST *p, *q。 p = p next。 q head 頭結點 結點 1 尾結點 結點 2 p 101 103 105 \0 q、 p都移到下一個結點 。 q q = head。 s next = p。 p = head next。 q void myinsert ( LST *head, int m ) { LST *p, *q, *s。 q head 頭結點 結點 1 尾結點 結點 2 新結點 s 101 103 105 \0 104 判斷是否找到插入點。 p q = q next。 p = p next。 head 頭結點 結點 1 尾結點 結點 2 新結點 s 101 103 105 \0 104 q q、 p都移到下一個結點。 q = head。 s = (LST*)malloc ( sizeof (LST) )。 } while ( p != NULL )。 p = head next。 105 移動 p,即使 p指向下一個結點。 p head 頭結點 結點 1 結點 2 尾結點 \0 101 103 105 移動 p,即使 p指向下一個結點。 p p = p next。 head 頭結點 結點 1 結點 2 尾結點 \0 101 103 105 輸出 p所指結點的 num成員值。 return head 。 printf (Input m: )。 while (m != 1 ) { p = (LST*)malloc ( sizeof (LST) )。 printf (建立鏈表,請輸入數(shù)值: \n )。 head 頭結點 num next 結點 1 num next 新結點 num next 101 q 103 p \0 LST *mycreat ( ) { int m。 q next = NULL。 head 頭結點 num next 結點 1 num next 新結點 num next 使 q指向新鏈表的最后一個結點。 p num = m。 head 頭結點 num next 結點 1 num next 新結點 num next 連接新結點和當前鏈表的最后結點 。 101 p q ( 3)編寫 mycreat( )函數(shù),并用此函數(shù)代替對應的空函數(shù)后運行程序。 head 頭結點 q num next 結點 1 num next 使 q指向新鏈表的最后一個結點。 p num = m。 head 頭結點 q num next 結點 1 num next 連接新結點和當前鏈表的最后結點。 ( 3)編寫 mycreat( )函數(shù),并用此函數(shù)代替對應的空函數(shù)后運行程序。 head = (LST *) malloc ( sizeof (LST) )。 } else printf ( “不存在 \n )。m)。 myprint ( head )。 scanf(%d, amp。 printf (“ 請選擇: ” )。 int k, m, choose。 可用 LST代替 struct lst ( 2)編寫主函數(shù),并先用空函數(shù)占被調函數(shù)的位置后測試 。 具體要求: ?調用 mycreat函數(shù) , 建立鏈表; ?