- 1
- 0
- 约2.33千字
- 约 3页
- 2018-05-05 发布于河南
- 举报
C语言建立链表删除插入等操作!
#include stdio.h
#include stdlib.h
#define LEN sizeof(struct ss)
typedef struct ss *pointer;
struct ss
{
int num;
int score;
pointer next;
};
int n=0;
struct ss *link(void)
{
struct ss *p,*pp,*head;
head=NULL;
p=pp=(struct ss *)malloc(LEN);
printf(Build linked:\n);
scanf(%d%d,p-num,p-score);
while(p-num!=0)
{
n++;
if(n==1) head=p;
else pp-next=p;
pp=p;
p=(struct ss *)malloc(LEN);
scanf(%d%d,p-num,p-score);
}
pp-next=NULL;
return head;
}
void print(struct ss *head)
{
struct ss *pq;
pq=head;
while(pq!=NULL)
{
printf(%30d %d\n,pq-num,pq-score);
pq=pq-next;
}
printf(%28dpoints!\n,n);
}
struct ss *del(struct ss *head)
{
int del_num;
struct ss *p1,*p2;
printf(Input del_num:);
scanf(%d,del_num);
if(head==NULL)
printf(Empty!no found!\n);
else
{
p1=head;
p2=head;
while((del_num!=p1-num)(p1-next!=NULL))
{p2=p1;p1=p1-next;}
if(del_num==p1-num)
{
if(p1==head) head=p1-next;
else p2-next=p1-next;
n--;
printf(del_num:%d\n,del_num);
}
else printf(No found %d\n,del_num);
}
return head;
}
struct ss *insert(struct ss *head)
{
struct ss *q1,*q2,*p0;
q1=head;
q2=head;
p0=(struct ss *)malloc(LEN);
printf(Input insert num and score:);
scanf(%d%d,p0-num,p0-score);
if(head==NULL)
{head=p0;p0-next=NULL;}
else
{
while((p0-numq1-num)(q1-next!=NULL))
{q2=q1;q1=q1-next;}
if(p0-num=q1-num)
{
if(q1==head) head=p0;
else q2-next=p0;
p0-next=q1;
}
else
{q1-next=p0;p0-next=NULL;}
}
printf(Insert num:%d %d\n,p0-num,p0-score);
n++;
return head;
}
int main()
{
struct ss *head;
int x;
head=NULL;
while(1)
{
printf(4.display\n);
printf(1.delete\n);
printf(3.insert\n);
printf(6.exit\n);
printf(9.build\n);
printf(Input:);
scanf(%d,x);
switch(x)
{
case 4 : print(head); continue;
您可能关注的文档
- 2013年河南农信社面试真题.doc
- 2013年益阳房地产市场走势预判及展望.docx
- 2013年秋二年级语文科质量分析.doc
- 2013年皮带长廊安全协议.doc
- 2013年秋期教研工作总结.doc
- 2013年第一季度安全生产例会主持词.doc
- 2013年职称英语(理工类)新增阅读理解及翻译(必考).doc
- 2013年课外活动工作计划.doc
- 2013年阿里巴巴排名规则详解].doc
- 2013年重型卡车市场经济环境预期分析.docx
- 2025-2026学年天津市和平区高三(上)期末数学试卷(含解析).pdf
- 2025-2026学年云南省楚雄州高三(上)期末数学试卷(含答案).pdf
- 2025-2026学年甘肃省天水市张家川实验中学高三(上)期末数学试卷(含答案).docx
- 2025-2026学年福建省厦门市松柏中学高二(上)期末数学试卷(含答案).docx
- 2025-2026学年广西钦州市高一(上)期末物理试卷(含答案).docx
- 2025-2026学年河北省邯郸市临漳县九年级(上)期末化学试卷(含答案).docx
- 2025-2026学年河北省石家庄二十三中七年级(上)期末历史试卷(含答案).docx
- 2025-2026学年海南省五指山市九年级(上)期末化学试卷(含答案).docx
- 2025-2026学年河北省唐山市玉田县九年级(上)期末化学试卷(含答案).docx
- 2025-2026学年河北省邢台市市区九年级(上)期末化学试卷(含答案).docx
原创力文档

文档评论(0)