链表题

声明:以下习题资料来自于BUPTSCS,请注意版权,仅可用于学习

问题 C: 实验11_11_链表匹配

时间限制: 1 Sec 内存限制: 128 MB
提交: 1740 解决: 564
[提交] [状态] [命题人:admin]
题目描述
已知两个由正整数组成的无序序列A、B,每个序列的元素个数未知,但至少有一个元素。你的任务是判断序列B是否是序列A的连续子序列。假设B是“1 9 2 4 18”,A是“33 64 1 9 2 4 18 7”,B是A的连续子序列;假设B是“1 9 2 4 18”,A是“33 1 9 64 2 4 18 7”,B不是A的连续子序列。
要求:
建立两个单链表A、B用于存储两个正整数序列,然后按照题目的要求,判断链表B是否是链表A的连续子序列。正整数的输入用-1作为结束标志,注意-1不算这个正整数序列中的元素(不要统计-1)。在程序结束前要释放链表A、B中的所有节点。
输入
依次输入两个乱序的正整数序列A、B,序列中元素个数未知,但每个序列至少有一个元素,并以输入“-1”结束,每个序列占一行。
输出
如果序列B是序列A的连续子序列,则输出“ListB is the sub sequence of ListA.”,否则输出“ListB is not the sub sequence of ListA.”。
数据最多的测试用例节点数在100这个数量级,所有整数可以用int型存储。
请注意输入输出格式。
样例输入 Copy
Sample 1:
5 4 3 2 1 -1
3 2 1 -1

Sample 2:
1 2 3 4 5 6 7 8 9 -1
1 2 3 4 5 6 7 8 0 -1
样例输出 Copy
Sample 1:
ListB is the sub sequence of ListA.

Sample 2:
ListB is not the sub sequence of ListA.

思路:分别写子函数进行问题分解
难点:类同于字符串比较,使用两个指针分别指两个序列进行比较,在A中找到与B相同的头,就接着比较接下来的数据。我认为难点在于,找到相同的头的地方要定义副本指针,用副本指针的移动比较接下来的数据。如果直接移动原来的两个指针,如果接下来的数据不相等,那么会丢失寻找第二次头相等的起始位置。

#include<stdio.h>
#include<stdlib.h>
typedef struct node{
	int data;
	struct node *nextptr;
}LISTUNIT;
LISTUNIT* listcreate();//建链表 
void destoryList(LISTUNIT **);//释放 
void listjudge(LISTUNIT**,LISTUNIT**);//判断是否是子序列 
int main()
{
	LISTUNIT *headaptr=NULL,*headbptr=NULL;
	headaptr=listcreate();
	headbptr=listcreate();
	listjudge(&headaptr,&headbptr);
	destoryList(&headaptr);
	destoryList(&headbptr);
	return 0;
}
LISTUNIT* listcreate()
{
	int num;
	LISTUNIT *currentptr=NULL,*headptr=NULL,*lastptr=NULL; 
	scanf("%d",&num);
	//printf("%d\n",num);
	headptr=malloc(sizeof(LISTUNIT));
	lastptr=headptr;
	while(num!=-1)
	{
		//len++;
		currentptr=malloc(sizeof(LISTUNIT)); /*分配结点内存*/ 
    	 if (currentptr!=NULL)//还可判断申请空间是否成功
		{/*插入结点*/
 	    	currentptr->data=num;	
      	    lastptr->nextptr=currentptr;  /*将结点连上链表尾结点*/
          	lastptr=currentptr;   /*使lastPtr指向当前链表的最后一个结点*/
    		
    	}
    	scanf("%d",&num);
	}
	lastptr->nextptr =NULL;
	return headptr;
}
void listjudge(LISTUNIT** headaptr,LISTUNIT** headbptr)
{
	LISTUNIT *currentptr=(*headaptr)->nextptr ,*current2ptr=(*headbptr)->nextptr ,*current3ptr=NULL,*current4ptr=NULL;
	int flag=0;
	while(currentptr)
	{
		if(currentptr->data ==current2ptr->data )
		{
			current3ptr=currentptr;
			current4ptr=current2ptr;//使用c3,c4代替,保证c,c2不变,以便下一次判断 
			while(current3ptr&&current4ptr)
			{
				if(current3ptr->data ==current4ptr->data )
				{
					current3ptr=current3ptr->nextptr ;
					current4ptr=current4ptr->nextptr ;//后移继续比较 
				}
				else break;//若不相等,退出循环 
			}
			if(!current4ptr)//检验退出循环的原因是否是链表b结束,是,则b是a的子序列 
			{
				flag=1;
				printf("ListB is the sub sequence of ListA.\n");
				break;
			}
		}
		currentptr=currentptr->nextptr ;
	}
	if(flag==0)
	printf("ListB is not the sub sequence of ListA.\n");
}
void destoryList(LISTUNIT **sPtr)
{
	LISTUNIT *headPtr=*sPtr,*tmpPtr=NULL;
	while(headPtr)
	{
		tmpPtr=headPtr;
		headPtr=headPtr->nextptr;
		free(tmpPtr);
	}
	*sPtr=NULL;
}

/*
Sample 1:
5 4 3 2 1 -1
3 2 1 -1

Sample 2:
1 2 3 4 5 6 7 8 9 -1
1 2 3 4 5 6 7 8 0 -1

*/

问题 D: 实验11_13_链表交换

时间限制: 1 Sec 内存限制: 128 MB
提交: 1141 解决: 516
[提交] [状态] [命题人:admin]
题目描述
已知一个正整数序列,序列元素个数未知,但至少有两个元素,你的任务是建立一个单链表用于存储这个正整数序列。然后实现交换此链表中任意指定的两段,第一段为[s1,t1],第二段[s2,t2]。s1、t1、s2、t2代表链表的第几个节点,且满足s1<=t1,s2<=t2,t1<s2,s2一定小于等于链表节点的总个数。正整数的输入用-1作为结束标志,注意-1不算这个正整数序列中的元素(不要统计-1)。最后将链表的全部节点释放。
输入
输入一个正整数序列,以输入“-1”结束,序列中元素个数未知,但输入“-1”前至少输入两个正整数。然后是四个整数,即为s1、t1、s2、t2。
输出
经过处理后的新链表,每个元素后有一个空格,注意最后一个元素后只有换行符。
数据最多的测试用例节点数在100这个数量级,所有整数可以用int型存储。
请注意输入输出格式。
样例输入 Copy
1 2 3 4 5 6 7 8 9 10 -1
1 1 4 7
样例输出 Copy
The new list is:4 5 6 7 2 3 1 8 9 10

思路:本题可将需要交换的区域看成链表的一个节点,不同的是,你需要通过给出的区域求出第一个节点的前驱指针,最后一个节点的后继指针。
在这里插入图片描述

#include<stdio.h>
#include<stdlib.h>
typedef struct node{
	int data;
	struct node *nextptr;
}LISTUNIT;
LISTUNIT* listcreate();
void destoryList(LISTUNIT **);
void changeList(LISTUNIT **);//交换
void listprint(LISTUNIT **);
int main()
{
	LISTUNIT *headptr=NULL;
	headptr=listcreate();
	changeList(&headptr);
	listprint(&headptr);
	destoryList(&headptr);
	return 0;
}
LISTUNIT* listcreate()
{
	int num;
	LISTUNIT *currentptr=NULL,*headptr=NULL,*lastptr=NULL; 
	scanf("%d",&num);
	//printf("%d\n",num);
	headptr=malloc(sizeof(LISTUNIT));
	lastptr=headptr;
	while(num!=-1)
	{
		//len++;
		currentptr=malloc(sizeof(LISTUNIT)); /*分配结点内存*/ 
    	 if (currentptr!=NULL)//还可判断申请空间是否成功
		{/*插入结点*/
 	    	currentptr->data=num;	
      	    lastptr->nextptr=currentptr;  /*将结点连上链表尾结点*/
          	lastptr=currentptr;   /*使lastPtr指向当前链表的最后一个结点*/
    		
    	}
    	scanf("%d",&num);
	}
	lastptr->nextptr =NULL;
	return headptr;
}
void changeList(LISTUNIT **headptr)
{
	int s1,s2,t1,t2,i;
	LISTUNIT *pre1ptr=*headptr,*pre2ptr=*headptr,*last1ptr=*headptr,*last2ptr=*headptr,*current1ptr=*headptr,*current2ptr=*headptr,*temp=NULL;
	scanf("%d%d%d%d",&s1,&t1,&s2,&t2);
	//将pre1,pre2,c1,c2,l1,l2移到恰当位置 
	for(i=0;i<s1-1;i++)
	{
		pre1ptr=pre1ptr->nextptr ;
	}
	for(i=0;i<s2-1;i++)
	{
		pre2ptr=pre2ptr->nextptr ;
	}
	for(i=0;i<s1;i++)
	{
		current1ptr=current1ptr->nextptr ;
	}
	for(i=0;i<s2;i++)
	{
		current2ptr=current2ptr->nextptr ;
	}
	for(i=0;i<t1;i++)
	{
		last1ptr=last1ptr->nextptr ;
	}
	for(i=0;i<t2;i++)
	{
		last2ptr=last2ptr->nextptr ;
	}
	pre1ptr->nextptr =pre2ptr->nextptr ;
	pre2ptr->nextptr =current1ptr;
	temp=last1ptr->nextptr ;
	last1ptr->nextptr =last2ptr->nextptr ;
	last2ptr->nextptr =temp;

}
void listprint(LISTUNIT **headptr)
{
	LISTUNIT *currentptr=(*headptr)->nextptr;
	printf("The new list is:");
	while(currentptr->nextptr )
	{
		printf("%d ",currentptr->data );
		currentptr=currentptr->nextptr ;
	}
	printf("%d\n",currentptr->data );
}
void destoryList(LISTUNIT **sPtr)
{
	LISTUNIT *headPtr=*sPtr,*tmpPtr=NULL;
	while(headPtr)
	{
		tmpPtr=headPtr;
		headPtr=headPtr->nextptr;
		free(tmpPtr);
	}
	*sPtr=NULL;
}

问题 A: 实验11_9_链表归并

时间限制: 1 Sec 内存限制: 128 MB
提交: 944 解决: 359
[提交] [状态] [命题人:admin]
题目描述
已知有两个递增的正整数序列A和B,序列中元素个数未知,同一序列中不会有重复元素出现,有可能某个序列为空。现要求将序列B归并到序列A中,且归并后序列A的数据仍然按递增顺序排列。如果序列B中某些数据在序列A中也存在,则这些数据所在节点仍然留在序列B中,而不被归并到序列A中;否则这些数据所在节点将从序列B中删除,添加到序列A中。
要求:
建立两个单链表A、B用于存储两个正整数序列,然后按照题目的要求,将链表B中的元素归并到链表A中。在归并的过程中,不要释放B中的节点空间、然后建立新节点,而要改变指针的指向,使元素从B中删除并添加到A中。正整数序列按照递增顺序输入,用-1作为结束标志,注意-1不算这个正整数序列中的元素(不要统计-1)。在程序结束前要释放链表A、B中的所有节点。
输入
依次输入两个递增的正整数序列A和B,序列元素的个数未知,但以输入“-1”结束,每个正整数序列占一行。
输出
处理后的链表A中的元素,占一行;然后是处理后的链表B中的元素,占一行。每行的每个元素后有一个空格,注意最后一个元素后只有换行符,如果某个链表为空则,则输出“There is no item in X list.”
数据最多的测试用例节点数在100这个数量级,所有整数可以用int型存储。
请注意输入输出格式。
样例输入 Copy
Sample 1:
1 3 4 5 6 7 -1
2 3 6 8 9 10 11-1

Sample 2:
-1
-1
样例输出 Copy
Sample 1:
The new list A:1 2 3 4 5 6 7 8 9 10 11
The new list B:3 6

Sample 2:
There is no item in A list.
There is no item in B list.

扫描二维码关注公众号,回复: 10130077 查看本文章

思路:归并B到A选好一个方向,要么一直判断B中元素能否左插,要么一直判断B中元素能否右插。
以下代码左插。

//有可能某个序列为空 ;递增 
#include<stdio.h>
#include<stdlib.h>
typedef struct list{
	int data;
	struct list *nextptr;
}LIST;
LIST* listCreate();
void listMerge(LIST**,LIST**);
void listPrint(LIST**,LIST**);
void listDestory(LIST**);
int main()
{
	LIST *Aheadptr=NULL,*Bheadptr=NULL;
	Aheadptr=listCreate();
	Bheadptr=listCreate();
	listMerge(&Aheadptr,&Bheadptr);
	listPrint(&Aheadptr,&Bheadptr);
	listDestory(&Aheadptr);
	listDestory(&Bheadptr);
	return 0;
 } 
LIST* listCreate()
{
	LIST *headptr=NULL,*currentptr=NULL,*lastptr=NULL;
	int num;
	headptr=malloc(sizeof(LIST));
	lastptr=headptr;
	lastptr->nextptr =NULL;
	scanf("%d",&num);
	while(num!=-1)
	{
		currentptr=malloc(sizeof(LIST));
		currentptr->data =num;
		lastptr->nextptr =currentptr;
		lastptr=currentptr;
		scanf("%d",&num);
	}
	lastptr->nextptr =NULL;
	return headptr;
}
void listMerge(LIST **Aheadptrptr,LIST **Bheadptrptr)
{
	LIST *first1ptr=NULL,*first2ptr=NULL,*pre1=NULL,*pre2=NULL,*temp=NULL;
	pre1=*Aheadptrptr;
	pre2=*Bheadptrptr;
	first1ptr=(*Aheadptrptr)->nextptr ;
	first2ptr=(*Bheadptrptr)->nextptr;
	/*if(!first1ptr->nextptr )
	printf("There is no item in A list.\n")*/
	while(first1ptr!=NULL&&first2ptr!=NULL)
	{
		if(first1ptr->data >first2ptr->data)//检验是否能左插 
		{
			pre1->nextptr =first2ptr;
			pre2->nextptr =first2ptr->nextptr ;
			first2ptr->nextptr =first1ptr;
			pre1=pre1->nextptr ;
			first1ptr=pre1->nextptr ;
			first2ptr=pre2->nextptr ;
		}
		else if(first1ptr->data == first2ptr->data )//相等则跳过 
		{
			pre2=pre2->nextptr ;
			first2ptr=pre2->nextptr ;
		}
		else//不能左插,A指针下移一位,继续检验能否左插 
		{
			pre1=pre1->nextptr ;
			first1ptr=pre1->nextptr ;
		}
	}
	if(first1ptr==NULL&&first2ptr!=NULL)
	{
		pre1->nextptr =first2ptr;
		pre2->nextptr =NULL;
	}
}
void listPrint(LIST **Aheadptrptr,LIST **Bheadptrptr)
{
	LIST *first1ptr=NULL,*first2ptr=NULL;
	first1ptr=(*Aheadptrptr)->nextptr ;
	first2ptr=(*Bheadptrptr)->nextptr;
	if(first1ptr==NULL)
	printf("There is no item in A list.\n");
	else
	{
		printf("The new list A:");
		while(first1ptr->nextptr !=NULL)
		{
			printf("%d ",first1ptr->data );
			first1ptr=first1ptr->nextptr ;
		}
		printf("%d\n",first1ptr->data );
	}
	if(first2ptr==NULL)
	printf("There is no item in B list.\n");
	else
	{
		printf("The new list B:");
		while(first2ptr->nextptr !=NULL)
		{
			printf("%d ",first2ptr->data );
			first2ptr=first2ptr->nextptr ;
		}
		printf("%d\n",first2ptr->data );
	}
	
}
void listDestory(LIST **sPtr)
{
	LIST *temp=NULL,*currentptr=*sPtr;
	while(currentptr!=NULL)
	{
		temp=currentptr;
		currentptr=currentptr->nextptr ;
		free(temp);
	}
	//free(currentptr);
	sPtr=NULL;
}
/*
Sample 1:
1 3 4 5 6 7 -1
2 3 6 8 9 10 11 -1

Sample 2:
-1
-1
*/

问题 B: 实验11_15_拆分链表

时间限制: 1 Sec 内存限制: 128 MB
提交: 894 解决: 321
[提交] [状态] [命题人:admin]
题目描述
已知有一个乱序的字符序列L,序列中的字符可能是英文字母、数字字符或其它字符,字符的个数未知,每个字符之间用空格分开。字符序列用“-1”作为输入结束标志,这里你要把-1当做一个字符串对待,并且不算作字符序列中的元素。如下即为一个合法的字符序列:“a c 3 b a d 6 , & j m 8 7 2 V -1”。你的任务是将这个字符序列拆分为三个独立的序列A、B和C,其中序列A存放序列L中的字母,序列B存放序列L中的数字,序列C存放序列L中的其他字符,然后,将序列A、B和C分别按照ASCII码的大小关系进行升序排序。最终序列L将变为空序列。
要求:
建立四个单链表,分别存储序列L、A、B、C中的元素。字符序列的输入用“-1”作为结束标志。建立链表L时,建议使用scanf(“%s”,s);来读取字符序列中的字符,即把单独的字符看做一个字符串读取。当L建立后,你要按照问题描述中所述,将L拆分为A、B、C三个链表,然后对每个链表都进行排序,这部分的操作都应该是对指针进行修改,而不是删除节点与建立新节点。在程序结束前要释放链表A、B、C中的所有节点。
输入
一个乱序的字符序列,序列元素的个数未知,以输入“-1”结束,输入“-1”前可能没有其它元素,每个字符序列占一行。
输出
链表A中的元素,占一行;然后是链表B中的元素,占一行。最后是链表C中的元素,占一行。每行的每个元素后有一个空格,注意最后一个元素后只有换行符,如果某个链表为空则,则输出“There is no item in X list.”
数据最多的测试用例节点数在100这个数量级。
请注意输入输出格式。
样例输入 Copy
Sample 1:
a c 3 b a d 6 , & j m 8 7 2 V -1

Sample 2:
z m v 1 a K 2 m p 9 a 0 a d -1
样例输出 Copy
Sample 1:
The list A is: V a a b c d j m
The list B is: 2 3 6 7 8
The list C is: & ,

Sample 2:
The list A is: K a a a d m m p v z
The list B is: 0 1 2 9
There is no item in C list.

思路:拆分成几个小函数分别写,本题主要困难在于:
1、用字符串来存储数据,在构造链表,比较时要使用字符串相关函数,如strcmp,strcpy;
2、写拆分函数时,界定数据范围要使用strcmp函数;
3、写排序函数时,循环的条件:头指针的副本遍历完整个链表。但是注意,不能直接使用counterptr=counterptr->nextptr,(counterptr=headptr->nextptr),因为在这个循环里的小循环结束后,counterptr所指向的数据不在原位置,即它指向的数据在原链表次序变了,使用它不等于空指针来判断会使大循环次数减少,从而得不到排好序的序列,解决方法见void listSort(LIST *headptr)

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct list{
	char str[2];
	struct list *nextptr;
}LIST;
LIST* listCreate();
void listSeparate(LIST **,LIST **,LIST **,LIST **);//用于拆分
void listSort(LIST *);
void destoryList(LIST **);
void listPrint(LIST**,LIST**,LIST**);
//void listprint(LIST *);//用于检验
int main()
{
	LIST *Lptr=NULL,*Aptr=NULL,*Bptr=NULL,*Cptr=NULL;
	Lptr=listCreate();
	listSeparate(&Lptr,&Aptr,&Bptr,&Cptr);
	//listPrint(&Aptr,&Bptr,&Cptr);
	listSort(Aptr);
	//listprint(Aptr);
	listSort(Bptr);
	listSort(Cptr);
	listPrint(&Aptr,&Bptr,&Cptr);
	destoryList(&Lptr);
	destoryList(&Aptr);
	destoryList(&Bptr);
	destoryList(&Cptr);
	return 0;
} 
LIST* listCreate()
{
	LIST *headptr=NULL,*currentptr=NULL,*lastptr=NULL;
	char s[2];
	headptr=malloc(sizeof(LIST));
	lastptr=headptr;
	lastptr->nextptr =NULL;
	scanf("%s",s);
	while(strcmp(s,"-1")!=0)
	{
		//printf("_%s",s);
		currentptr=malloc(sizeof(LIST));
		strcpy(currentptr->str,s) ;
		lastptr->nextptr =currentptr;
		lastptr=currentptr;
		scanf("%s",s);
	}
	lastptr->nextptr =NULL;
	return headptr;
}
void listSeparate(LIST **Lheadptrptr,LIST **Aheadptr,LIST **Bheadptr,LIST **Cheadptr)
{
	//printf("Y\n");
	LIST *f1ptr=(*Lheadptrptr)->nextptr,*f2ptr=NULL,*f3ptr=NULL,*f4ptr=NULL;
	//printf("00_%s\n",f1ptr->str );
	*Aheadptr=(LIST *)malloc(sizeof(LIST));
	*Bheadptr=(LIST *)malloc(sizeof(LIST));
	*Cheadptr=(LIST *)malloc(sizeof(LIST));
	(*Aheadptr)->nextptr =NULL;
	(*Bheadptr)->nextptr =NULL;
	(*Cheadptr)->nextptr =NULL;
	f2ptr=*Aheadptr;
	f3ptr=*Bheadptr;
	f4ptr=*Cheadptr;
	//printf("0_%s\n",f1ptr->str );
	while(f1ptr!=NULL)
	{
		//printf("_%s\n",f1ptr->str );
		if((strcmp(f1ptr->str ,"A")>=0 && strcmp(f1ptr->str,"Z")<=0) ||(strcmp(f1ptr->str ,"a")>=0 && strcmp(f1ptr->str,"z")<=0) )
		{
			//printf("A_%s\n",f1ptr->str );
			f2ptr->nextptr =f1ptr;
			(*Lheadptrptr)->nextptr=f1ptr->nextptr ;
			f1ptr->nextptr =NULL;				
			f1ptr=(*Lheadptrptr)->nextptr;
			f2ptr=f2ptr->nextptr ;
		}
		else if((strcmp(f1ptr->str ,"0")>=0 && strcmp(f1ptr->str,"9")<=0))
		{
			//printf("B_%s\n",f1ptr->str );
			f3ptr->nextptr =f1ptr;
			(*Lheadptrptr)->nextptr=f1ptr->nextptr ;
			f1ptr->nextptr =NULL;				
			f1ptr=(*Lheadptrptr)->nextptr;
			f3ptr=f3ptr->nextptr ;
		}
		else
		{
			//printf("C_%s\n",f1ptr->str );
			f4ptr->nextptr =f1ptr;
			(*Lheadptrptr)->nextptr=f1ptr->nextptr ;
			f1ptr->nextptr =NULL;				
			f1ptr=(*Lheadptrptr)->nextptr;
			f4ptr=f4ptr->nextptr ;
		}
	}
	
}
void listSort(LIST *headptr)
{
	LIST *currentptr=NULL,*counterptr=NULL,*previousptr=NULL,*current2ptr=NULL,*counter2ptr=NULL;
	int num=0,i;
	counterptr=headptr->nextptr  ;
	while(counterptr!=NULL)
	{
		previousptr=headptr;
		currentptr=previousptr->nextptr ;
		current2ptr=currentptr->nextptr ;
		//counter2ptr=headptr->nextptr  ;
		while(current2ptr!=NULL)
		{
			if(strcmp(currentptr->str,current2ptr->str) > 0)
			{
				previousptr->nextptr =current2ptr;
				currentptr->nextptr =current2ptr->nextptr ;
				current2ptr->nextptr =currentptr;
				previousptr=previousptr->nextptr ;
				current2ptr=currentptr->nextptr ;
			}
			else
			{
				previousptr=previousptr->nextptr ;
				currentptr=currentptr->nextptr ;
				current2ptr=current2ptr->nextptr ;
			}
			//counter2ptr=counter2ptr->nextptr ;
			//listprint(headptr);
		}
		/******************************************
		以下是难点解决方案
		*******************************************/
		num++;
		//listprint(headptr);
		counterptr=headptr->nextptr ;
		for(i=0;i<num;i++)
		{
			counterptr=counterptr->nextptr ;
		}		
		//printf("_%s\n",counterptr->str );
	}		
}

void destoryList(LIST **sPtr)
{
	LIST *headPtr=*sPtr,*tmpPtr=NULL;
	while(headPtr)
	{
		tmpPtr=headPtr;
		headPtr=headPtr->nextptr;
		free(tmpPtr);
	}
	*sPtr=NULL;
}
void listPrint(LIST **Aheadptrptr,LIST **Bheadptrptr,LIST **Cheadptrptr)
{
	LIST *first1ptr=NULL,*first2ptr=NULL,*first3ptr=NULL;
	first1ptr=(*Aheadptrptr)->nextptr ;
	first2ptr=(*Bheadptrptr)->nextptr;
	first3ptr=(*Cheadptrptr)->nextptr;
	if(first1ptr==NULL)
	printf("There is no item in A list.\n");
	else
	{
		printf("The list A is: ");
		while(first1ptr->nextptr !=NULL)
		{
			printf("%s ",first1ptr->str );
			first1ptr=first1ptr->nextptr ;
		}
		printf("%s\n",first1ptr->str );
	}
	if(first2ptr==NULL)
	printf("There is no item in B list.\n");
	else
	{
		printf("The list B is: ");
		while(first2ptr->nextptr !=NULL)
		{
			printf("%s ",first2ptr->str );
			first2ptr=first2ptr->nextptr ;
		}
		printf("%s\n",first2ptr->str );
	}
	if(first3ptr==NULL)
	printf("There is no item in C list.\n");
	else
	{
		printf("The list C is: ");
		while(first3ptr->nextptr !=NULL)
		{
			printf("%s ",first3ptr->str );
			first3ptr=first3ptr->nextptr ;
		}
		printf("%s\n",first3ptr->str );
	}
}
void listprint(LIST *headptr)
{
	LIST *currentptr=NULL;
	currentptr=headptr->nextptr ;
	printf("The new list is:");
	while(currentptr->nextptr !=NULL)
	{
		printf("%s ",currentptr->str );
		currentptr=currentptr->nextptr ;
	}
	printf("%s\n",currentptr->str );
}
/*
Sample 1:
a c 3 b a d 6 , & j m 8 7 2 V -1

Sample 2:
z m v 1 a K 2 m p 9 a 0 a d -1
*/

————————————————
最后悄咪咪贴上自己的做题过程,倒数第二次是因为‘:’后少了个空格,心塞塞
在这里插入图片描述

发布了26 篇原创文章 · 获赞 18 · 访问量 1625

猜你喜欢

转载自blog.csdn.net/qq_40774136/article/details/104881530
今日推荐