c语言综合测试的题目 菜鸟求助

来源:百度知道 编辑:UC知道 时间:2024/07/04 03:18:42
实验目的;
学习用指针构造链表,操作链表
实验内容:
输入两个非降序列,转换成两个非升虚列,合并成一个非升序列。
基本要求:
用链表实现。

创建一个链表。

/*creat a list*/
#include "stdlib.h"
#include "stdio.h"
#include "conio.h"
struct list
{
int data;
struct list *next;
};
typedef struct list node;
typedef node *link;
void main()
{
link ptr,head;
int num,i;
ptr=(link)malloc(sizeof(node));
ptr=head;
printf("please input 5 numbers==>\n");
for(i=0;i<=4;i++)
{
scanf("%d",&num);
ptr->data=num;
ptr->next=(link)malloc(sizeof(node));
if(i==4) ptr->next=NULL;
else ptr=ptr->next;
}
ptr=head;
while(ptr!=NULL)
{
printf("The value is ==>%d\n",ptr->data);
ptr=ptr->next;
}
getch();
}

连接两个链表。
#include "stdlib.h"
#include "stdio.h"
#include "conio.h"
struct l