国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

自己寫的一個(gè)鏈表綜合程序

2019-11-17 05:27:42
字體:
供稿:網(wǎng)友
#include<stdio.h>
#include<malloc.h>
#include<string.h>typedef strUCt elem/*定義接點(diǎn)*/
  {
   char name[10];
   struct elem *next;
  }create;create *head,*van,*cur,*temp;/*定義頭接點(diǎn)(head),前驅(qū)接點(diǎn)(van),當(dāng)前接點(diǎn)(cur),零時(shí)接點(diǎn)(temp)*/void menu()/*創(chuàng)建菜單*/
  {
      printf("/t/t/t2.插入新元素------[2]/n");
   printf("/t/t/t3.刪除舊元素------[3]/n");
   printf("/t/t/t4.查找舊元素------[4]/n");
   printf("/t/t/t5.倒置原鏈表------[5]/n");
   printf("/t/t/t6.顯示所有元素----[6]/n");
   printf("/t/t/t7.退出------------[7]/n/n");
   printf("請(qǐng)選擇(1~7): ");
  }
void new(int n)/*創(chuàng)建新鏈表,參數(shù)n為鏈表長(zhǎng)度*/
  {
   int i;
   printf("/n");
   if((head=(create *)malloc(sizeof(create)))==NULL)/*定義頭接點(diǎn)*/
     {
      printf("/n不能創(chuàng)建鏈表");
      exit(1);
     }
   van=head;/*將前驅(qū)接點(diǎn)指針指向頭接點(diǎn)*/
   for(i=1;i<=n;i++)
     {
      if((cur=(create *)malloc(sizeof(create)))==NULL)/*定義新接點(diǎn)*/
        {
         printf("/n不能創(chuàng)建鏈表");
         exit(1);
        }
      cur->next=NULL;/*將當(dāng)前接點(diǎn)的后繼指針置空*/
      van->next=cur;/*連接接點(diǎn)*/
      printf("輸入第%d個(gè)人的名字: ",i);
      scanf("%s",&cur->name);/*輸入當(dāng)前接點(diǎn)的數(shù)據(jù)域內(nèi)容*/
      van=cur;
     }
  }create *research(char searchname[10])/*查找接點(diǎn)函數(shù)*/
  {
   van=head;
   temp=head->next;
   while(temp!=NULL)
     {
      if(strcmp(temp->name,searchname)==0)
        {
         return(temp);
        }
      else
        {
         van=temp;
         temp=temp->next;
        }
     }
   return(temp);
  }void print()/*顯示鏈表函數(shù)*/
  {
   temp=head->next;
   printf("/n");
   while(temp!=NULL)
     {
      printf("%s  ",temp->name);
      temp=temp->next;
     }
  }
void insert(create *insert_point,char insert_name[10])/*插入接點(diǎn)函數(shù)*/
  {
   if((cur=(create *)malloc(sizeof(create)))==NULL)
     {
      printf("/n不能創(chuàng)建鏈表");
      exit(1);
     }
   stpcpy(cur->name,insert_name);
   cur->next=insert_point->next;
   insert_point->next=cur;
  }
void delete(create *delete_point)/*刪除接點(diǎn)函數(shù)*/
  {
   van->next=delete_point->next;
   free(delete_point);
  }
int turnlist()/*倒置鏈表函數(shù)*/
  {
   van=head->next;
   cur=van->next;
   van->next=NULL;
   while(cur!=NULL)
     {
      temp=cur->next;
      cur->next=van;
      van=cur;
      cur=temp;
     }
   head->next=van;
  }  
main()
{
 int select,length;
 char tempname[10];
 head=NULL;
 while(1)
   {
    clrscr();
    menu();
    scanf("%d",&select);
    switch(select)
      {
       case 1:             
              printf("/n請(qǐng)輸入你要建立的鏈表的長(zhǎng)度: ");
              scanf("%d",&length);
              new(length);
              printf("/n鏈表已創(chuàng)建,按任意鍵返回/n");
              getch();
              break;     
       case 2:         
              if(head==NULL)
                {
                 printf("/n請(qǐng)先建立鏈表,按任意鍵返回 /n");
                 getch();
                 break;
                }   
              printf("/n以下為鏈表中原有元素: ");
              print();
              printf("/n請(qǐng)輸入你要在哪個(gè)名字后面插入新名字: ");
              scanf("%s",&tempname);
              temp=research(tempname);
              if((temp=research(tempname))==NULL)
                {
                 printf("/n沒有找到你要輸入的名字,按任意鍵返回/n");
                 getch();
                }
              else
                {
                 printf("/n請(qǐng)輸入你要插入的名字: ");
                 scanf("%s",&tempname);
                 insert(temp,tempname);
                 printf("/


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 许昌县| 安塞县| 满城县| 河西区| 巴东县| 镇远县| 武川县| 杂多县| 南充市| 越西县| 宁陕县| 乌拉特中旗| 安阳县| 唐河县| 务川| 洛隆县| 平利县| 云安县| 荆门市| 桐柏县| 克拉玛依市| 龙岩市| 成安县| 博爱县| 揭西县| 乌兰察布市| 平潭县| 漾濞| 柏乡县| 阳城县| 洮南市| 景德镇市| 马关县| 雷山县| 浦北县| 宁城县| 杭州市| 宝丰县| 清远市| 明光市| 万安县|