文档下载 文档下载导航
设为首页 | 加入收藏
搜索 请输入内容:  
 导航当前位置: 文档下载 > 所有分类 > IT/计算机 > C 数据结构 实现插入删除循环
侵权投诉

C 数据结构 实现插入删除循环

C 数据结构 实现插入删除循环

typedef datatype;
typedef struct link_node
{
datatype info;
struct link_node *next;
}node;
void printflink(node *head)
{
node *p;
int n=0;
while(p->next != NULL)
{
printf("%5d",p->next->info);
p= p->next;
n++;
if(n%5==0)
printf("\n");

}
}
node *createlink(node *head)
{
node *p,*q;
int flag=1,n;
head->next=NULL;
q=head;
bb:printf("input a info between -32768--32767 you want,input Enter between two info !\nThen put int ZERO(0) to finish:\n");
while(flag)
{
scanf("%d",&n);
if(n<-32767||n>32767)
{
printf("the info you insert may be too big or too small !!\n");
goto bb;
}
else{
if(n!=0)
{
p=(node*)malloc(sizeof(node));
p->info=n;
p->next=NULL;
q->next=p;
q =p;
p = p->next;
}
else
flag=0;
}
}


return head;
}

node *insert(node *head)
{
int n;
int flag=1;
printf(" Insert data you want !youcan insert one,two,OR any more you want,\n input Enter between every two info,and then input ZERO(0)TO finish:\n");
while(flag)
{
node *p=head,*q;
scanf("%d",&n);
if(n!=0)
{
q=(node*)malloc(sizeof(node));
q->info=n;
q->next=p->next;
p->next=q;
}
else flag=0;
}
return head;
}


node *dellink(node *head)
{
int x;
node *pre=head,*q;
printf("\ninsert a info you want to delete!:\n");
scanf("%d",&x);
q=head->next;
while(q&&q->info!=x)
{
pre=q;q=q->next;
}
if(q->info==x)
{
pre->next=q->next;
free(q);
printf("\n the data of this link is:\n");

}
else
printf("\n !!!the link do not have this info!!!!!\n\n");

return head;
}


node *asclink(node *head,int n )
{
int i,j;
node *p,*q;
p=head->next;
q=p->next;
for(i=n;i>1;i--)
{
for(j=1;j<n;j++)
{
if((p->info)>(q->info))
{
int t;t=p->info;
p->info=q->info;
q->info=t;
p=q;
q=q->next;
}
else
{p=q;q=q->next;}
}
p=head->next;
q=p->next;
}
return head;
}

int returnI(node *head)
{
int i=0;
node *q=head;
while(q->next != NULL)
{
q = q->next;
i++;
}
return i;
}
void ReInsert(node *head,char m)
{
char n;
printf("\n Do you want to insert any info ? Please input 'y' or 'n':");
n=scanf("%d",&n);
while((n=getchar())==m)
{
if(n==m)
{
insert(head);
asclink(head,returnI(head));
printf("\n the data of this link is:\n");
printflink(head);
}
printf("\n Do you want to insert any info ? Please input 'y' or 'n':");
n=scanf("%d",&n);

}
}

void main

第1页

你可能喜欢

  • 同济第五版线性代数答案
  • 概率论与数理统计答案
  • 毛概复习资料大全
  • 数据结构试题及答案
  • 成语归类大全
  • 电大数据结构

热门文档

相关文档

站点地图 | 文档上传 | 侵权投诉 | 手机版
本站所有资源均来自互联网,本站只负责收集和整理,均不承担任何法律责任,如有侵权等其它行为请联系我们.
文档下载 Copyright 2013 doc.guandang.net All Rights Reserved.  -  email