⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 1.2.c

📁 自己写的数据结构课程程序
💻 C
字号:
#include<stdio.h>
#define LENGTH 100
#define INCREASE 10
#define NULL 0
struct linklist
{int data;
 struct linklist *next;
};
struct linklist L;
void Init_linklist()
{int i;
 char c;
 struct linklist *s,*r;
 L.next=NULL;
 r=&L;
 for(i=0;i<LENGTH;i++)
   {printf("please input the data:\n");
    s=(struct linklist *)malloc(sizeof(L));
    scanf("%d",&s->data);
    getchar();
    s->next=NULL;
    r->next=s;
    r=s;
    printf("continue?(y/n)\n");
    scanf("%c",&c);
    if(c=='n')
    i=LENGTH;
   }
}
struct linklist* Seek_linklist(int e)
{struct linklist *pre,*p;
 pre=&L;
 p=L.next;
 while(p!=NULL&&p->data!=e)
   {pre=p;
    p=p->next;
   }
 if(p==NULL)
   return NULL;
 else
   return pre;
}
void Insert_linklist()
{int e;
 struct linklist *s,*pre;
 printf("please input the element before which you want insert:\n");
 scanf("%d",&e);
 pre=Seek_linklist(e);
 if(pre==NULL)
   printf("the element is wrong!");
 else
   {s=(struct linklist*)malloc(sizeof(L));
    printf("please input the data:\n");
    scanf("%d",&s->data);
    s->next=pre->next;
    pre->next=s;
   }

}
void Delete_linklist()
{int e;
 struct linklist *pre,*p;
 printf("please input the element which you want delete:\n");
 scanf("%d",&e);
 getchar();
 pre=Seek_linklist(e);
 p=pre->next;
 pre->next=pre->next->next;
 free(p);
}

void Display_linklist()
{struct linklist *p=L.next;
 while(p!=NULL)
   {printf("%d ",p->data);
    p=p->next;
   }
 printf("\n");
}
void main(void)
{Init_linklist();
 Display_linklist();
 Insert_linklist();
 Display_linklist();
 Delete_linklist();
 Display_linklist();
 getchar();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -