我思故我在系列—数据结构面试NO.24(题目搜集整理者JULY,非常感谢!!)
来源:互联网 发布:淘宝卖家订单旗子标记 编辑:程序博客网 时间:2024/06/10 22:41
第24题:
1.反转链表
2.合并链表。
#include<stdio.h>
#include<stdlib.h>#include<assert.h>
typedef struct SListNode
{
int data;
struct SListNode *next;
}Lnode,*Slinklist;
Slinklist Createlink()
{
int input;
Slinklist Head=NULL;
Slinklist pcur=NULL;
Slinklist qend=NULL;
Head=( Slinklist)malloc(sizeof(Lnode));//申请空间
Head->next=NULL;
printf("please input data:");
scanf("%d",&input);
while(input!=0)
{
pcur=( Slinklist)malloc(sizeof(Lnode));//申请空间
pcur->data=input;
pcur->next=NULL;
if(Head->next==NULL)
{
Head->next=pcur;
}
else
{
qend->next=pcur;
}
qend=pcur;
printf("please input data:");
scanf("%d",&input);
}
return Head;
}
Slinklist Reversion(Slinklist H)
{
assert(H!=NULL);
Slinklist p=H->next,q;
H->next=NULL;
while(p!=NULL)
{
q=p; //q指针插入
p=p->next;
q->next=H->next;
H->next=q;
}
return H;
}
Slinklist Combine(Slinklist H1,Slinklist H2)/*H1的尾结点连接H2->next.并且释放,H2的头指针*/
{
Slinklist H=H1;
while(H->next!=NULL)
{
H=H->next;
}
H->next=H2->next;
free(H2);
H2=NULL;
return H1;
}
void display(Slinklist H)
{
assert(H!=NULL);
Slinklist cur=H->next;
while(cur!=NULL)
{
printf("%d,",cur->data);
cur=cur->next;
}
}
void free_sLink(Slinklist Head)
{
Slinklist cur=Head;
while(cur->next !=NULL )
{
cur=Head;
Head=Head->next;
free(cur);
cur=NULL;
}
free(Head);
Head=NULL;
}
int main(int argc,char* argv[])
{
Slinklist H0;
Slinklist H00;
H0=Createlink();
display(H0);
printf("\n");
H00=Createlink();
display(H00);
printf("\n");
Reversion(H0);
display(H0);
printf("\n");
H0=Combine(H0,H00);
display(H0);
return 1;
}
- 我思故我在系列—数据结构面试NO.24(题目搜集整理者JULY,非常感谢!!)
- 我思故我在系列—数据结构面试NO.22,NO.23题(题目搜集整理者JULY,非常感谢!!)
- 我思故我在系列—数据结构面试NO.15(题目搜集整理者JULY,非常感谢!!)
- 我思故我在系列—数据结构面试NO.27题(题目搜集整理者JULY,非常感谢!!)
- 我思故我在系列—数据结构面试NO.29题(题目搜集整理者JULY,非常感谢!!)
- 我思故我在系列—数据结构面试NO.30题(题目搜集整理者JULY,非常感谢!!)
- 我思故我在系列—数据结构面试NO.35题(题目搜集整理者JULY,非常感谢!!)
- 我思故我在系列—数据结构NO.31,NO.32(题目搜集整理者JULY,非常感谢!!)
- 我思故我在系列—数据结构NO.33,NO.34(题目搜集整理者JULY,非常感谢!!)
- 我思故我在系列—数据结构题(题目搜集整理者july,非常感谢!)
- 我思故我在系列——数据结构NO.16题(题目搜集整理者JULY,非常感谢!!)
- 我思故我在系列—数据结构面试题NO.17(题目搜集整理者JULY,非常感谢!!)
- 我思故我在系列—数据结构NO.21题(题目搜集整理者JULY,非常感谢!!)
- 我思故我在系列—数据结构NO.25题(题目搜集整理者JULY,非常感谢!!)
- 我思故我在系列—数据结构NO.26题(题目搜集整理者JULY,非常感谢!!)
- 我思故我在系列—数据结构NO.28题(题目搜集整理者JULY,非常感谢!!)
- 我思故我在系列—数据结构题NO.36(题目搜集整理者july,非常感谢!!)
- 我思故我在系列—数据结构面试14题(题目搜集整理者JULY,非常感谢!!)
- Scrum小结
- jquery给iframe添加内容
- Ipod touch 2G 破解成功 by greenpois0n RC6.1 (win)
- http://acm.hdu.edu.cn/showproblem.php?pid=1162
- myeplise查看相应的eclipse版本
- 我思故我在系列—数据结构面试NO.24(题目搜集整理者JULY,非常感谢!!)
- 不用递归的方法计算米粒的个数和每个米粒的面积,matlab实现
- sprint 5 的第一周
- http协议请求响应详解
- 秋天的银杏叶
- Chord算法
- 11g EM 出错处理
- 我思故我在系列—数据结构NO.25题(题目搜集整理者JULY,非常感谢!!)
- 排序大集锦(一):构建健壮的快速排序