| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1678 人关注过本帖
标题:顺序表插入与删除.
只看楼主 加入收藏
如梦
Rank: 1
等 级:新手上路
帖 子:47
专家分:0
注 册:2005-9-21
收藏
得分:0 
自己看书呀

学习不可少
2005-10-15 08:54
firstlijia
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2005-10-8
收藏
得分:0 

struct student {int num; int score; struct student *next;}; struct student *del(struct student *head,int num) {struct student *p1,*p2; if(head==NULL) {printf("\nlist null! \n"); } p1=head; while(num!=p1->num&&p1->next!=NULL) {p2=p1; p1=p1->next;} if(num==p1->num) {if(p1==head) head=p1->next; else p2->next=p1->next; printf("delete :%d\n",num); n=n-1;} else printf("%d not been found!\n",num); return(head);}

struct student *insert(struct student *head,struct student *stud) {struct student *p0,*p1,*p2;

p1=head; p0=stud; if(head==NULL) {head=p0;p0->next=NULL;} else {while((p0->num>p1->num)&&(p1->next!=NULL)) {p2=p1;p1=p1->next;} if(p0->num<=p1->num) {if(head==p1) head=p0; else p2->next=p0; p0->next=p1; } else { p1->next=p0; p0->next=NULL; } }

return(head); }


2005-10-18 12:12
爱上夏天的雨
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2007-5-17
收藏
得分:0 
2007-06-18 10:30
twsgl
Rank: 1
等 级:新手上路
帖 子:136
专家分:5
注 册:2007-6-15
收藏
得分:0 

struct student
{int num;
int score;
struct student *next;};
struct student *del(struct student *head,int num)
{struct student *p1,*p2;
if(head==NULL)
{printf("\nlist null! \n");
} p1=head;
while(num!=p1->num&&p1->next!=NULL)
{p2=p1;
p1=p1->next;}
if(num==p1->num)
{if(p1==head)
head=p1->next;
else
p2->next=p1->next;
printf("delete :%d\n",num);
n=n-1;}
else
printf("%d not been found!\n",num);
return(head);}

struct student *insert(struct student *head,struct student *stud)
{struct student *p0,*p1,*p2;

p1=head;
p0=stud;
if(head==NULL)
{head=p0;p0->next=NULL;}
else
{while((p0->num>p1->num)&&(p1->next!=NULL))
{p2=p1;p1=p1->next;}
if(p0->num<=p1->num)
{if(head==p1)
head=p0;
else
p2->next=p0;
p0->next=p1;
}
else
{ p1->next=p0;
p0->next=NULL; }
}

return(head);
}
我这样的问题发出好多次了
不过这好象是数据结构的题
怎么来这了

2007-06-18 17:23
twsgl
Rank: 1
等 级:新手上路
帖 子:136
专家分:5
注 册:2007-6-15
收藏
得分:0 
数据结构的

struct student
{int num;
int score;
struct student *next;};
struct student *del(struct student *head,int num)
{struct student *p1,*p2;
if(head==NULL)
{printf("\nlist null! \n");
} p1=head;
while(num!=p1->num&&p1->next!=NULL)
{p2=p1;
p1=p1->next;}
if(num==p1->num)
{if(p1==head)
head=p1->next;
else
p2->next=p1->next;
printf("delete :%d\n",num);
n=n-1;}
else
printf("%d not been found!\n",num);
return(head);}

struct student *insert(struct student *head,struct student *stud)
{struct student *p0,*p1,*p2;

p1=head;
p0=stud;
if(head==NULL)
{head=p0;p0->next=NULL;}
else
{while((p0->num>p1->num)&&(p1->next!=NULL))
{p2=p1;p1=p1->next;}
if(p0->num<=p1->num)
{if(head==p1)
head=p0;
else
p2->next=p0;
p0->next=p1;
}
else
{ p1->next=p0;
p0->next=NULL; }
}

return(head);
}

或者
void insert_pos_sequence_list(sequence_list *slt,int position,datatype x)
{ int i;
if(slt->size==maxsize)
{printf("\n顺序表是满的!没法插入!");exit(1);}
if(position<0||position>slt->size)
{printf("\n指定的插入位置不存在!");exit(1);}
for(i=slt->size;i>position;i--) slt->a[i]=slt->a[i-1];
slt->a[position]=x;
slt->size++;
}

2007-06-18 21:55
月徘徊
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2007-7-10
收藏
得分:0 
鸟啊,这是在单链表里面的啊

2007-07-18 21:48
快速回复:顺序表插入与删除.
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.036500 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved