Known to have a character sequence order L, in a sequence of characters can be letters, Numbers or other characters characters, the number of characters is unknown, separated by Spaces between each character, character sequence with "1" as a symbol input end, here are you going to treat - 1 as a string, and does not count as elements in a sequence of characters, the following is a valid character sequence: "a c 3 b a d 6, & amp; J m 8 July 2 V - 1 ", your task is to the character sequence into three separate sequence. A, B and C, deposit which sequence is A sequence of letters, L series B to store the number in the sequence of L, C stored sequences L of other characters, then, will sequence. A, B and C, respectively, according to the relationship between the size of the ASCII ascending order, the final sequence, L will become empty
Requirements:
To build four singly linked lists, are stored sequence L, A, B, C, the elements of the character sequence input by "1" as end mark, establishing list L, it is recommended to use the scanf (" % s ", s); To read the characters in A character sequence, that is, to read as A string, the characters of single when L set up, you should be described according to the problems, will L into A, B, C three linked list, and then for each list is sorted, this part of the operation should be to modify A pointer, rather than remove nodes and create new nodes, to release the list before the end of the program. A, B, C of all nodes,
Sample 1:
A 3 c b a d 6, & amp; J m 8 7 2 V - 1
Sample 2:
Z m, 2 m p 9 v 1 a K a 0 a d - 1
O
Sample 1:
The list is A: V A A b c d j m
The list is B: 2, 3, 6, 7, 8
The list is: C & amp; ,
Sample 2:
The list is A: K aa A d m m p v z
The list is B: 0 1 2 9
There is no item in the list C.
CodePudding user response:
My code:/* problem B: experimental 11 _15_ split list */
# include
# include
Typedef struct byte {
Char data;
Struct byte * nextPtr;
} the ITEM;
ITEM * build (void);
Void destroy (ITEM * headPtr);
Void change (ITEM * headPtr);
Void break1 (ITEM * headPtr, ITEM * aPtr, ITEM * bPtr, ITEM * cPtr, ITEM aPtrPtr * *, * * bPtrPtr ITEM, the ITEM * * cPtrPtr);
Void print (ITEM * headPtr);
Int main (void) {
BPtr aPtr headPtr ITEM * and * and * and * cPtr;
BPtrPtr ITEM aPtrPtr * *, * * and * * cPtrPtr;
HeadPtr=build ();
APtr=(ITEM *) malloc (sizeof (ITEM));
APtr - & gt; NextPtr=NULL;
APtrPtr=& amp; APtr;
BPtr=(ITEM *) malloc (sizeof (ITEM));
BPtr - & gt; NextPtr=NULL;
BPtrPtr=& amp; BPtr;
CPtr=(ITEM *) malloc (sizeof (ITEM));
CPtr - & gt; NextPtr=NULL;
CPtrPtr=& amp; CPtr.
Break1 (headPtr aPtr, bPtr cPtr, aPtrPtr, bPtrPtr, cPtrPtr);
Change (aPtr); Change (bPtr); Change (cPtr);
If (aPtr) {
Printf (" The list A is: ");
Print (aPtr - & gt; NextPtr);
printf("\n");
}
The else
Printf (" There is no item in A list. \ n ");
If (bPtr) {
Printf (" The list is B: ");
Print (bPtr - & gt; NextPtr);
printf("\n");
}
The else
Printf (" There is no item in the list B. \ n ");
If (cPtr) {
Printf (" The list is C: ");
Print (cPtr - & gt; NextPtr);
}
The else
Printf (" There is no item in the list. The C ");
Destroy (headPtr);
Destroy (aPtr);
Destroy (bPtr);
Destroy (cPtr);
APtrPtr=NULL;
BPtrPtr=NULL;
CPtrPtr=NULL;
}
//create the list function
ITEM * build (void) {
The current ITEM * head=NULL, * and * pre=NULL;
Char n;
The scanf (" % c ", & amp; n);
While ((int) n!=45) {//distinguish - 1
Current=(ITEM *) malloc (sizeof (ITEM));
Current - & gt; data=https://bbs.csdn.net/topics/n;
if(! The head)
The head=pre=current;
The else {
The pre - & gt; NextPtr=current;
The pre=current;
}
The scanf (" % c ", & amp; n);
}
The pre - & gt; NextPtr=NULL;
return head;
}
//release chain table function
Void destroy (ITEM * headPtr) {
ITEM * tempPtr;
While (headPtr) {
TempPtr=headPtr;
HeadPtr=headPtr - & gt; NextPtr;
Free (tempPtr);
}
}
//list sort function
Void change (ITEM * headPtr) {
Char min, a;
TempPtr currentPtr=headPtr ITEM * and * and * minPtr;
While (currentPtr) {
TempPtr=currentPtr;//record the current position
Min=currentPtr - & gt; The data;
MinPtr=currentPtr;//initialize the minimum value, a pointer to the minimum value
While (tempPtr) {
If (tempPtr - & gt; The data & lt; Min) {
Min=tempPtr - & gt; The data;
MinPtr=tempPtr;
}
TempPtr=tempPtr - & gt; NextPtr;
}//to find the lowest value of the current and subsequent list instead of a pointer
A=currentPtr - & gt; The data;
CurrentPtr - & gt; Data=https://bbs.csdn.net/topics/min;
MinPtr - & gt; Data=https://bbs.csdn.net/topics/a;//will be the minimum and the values in the current exchange
CurrentPtr=currentPtr - & gt; NextPtr;//the current jump to the next list
}
MinPtr=NULL;
TempPtr=NULL;
}
//segmentation chain table function
Void break1 (ITEM * headPtr, ITEM * aPtr, ITEM * bPtr, cPtr ITEM * and * * aPtrPtr ITEM, ITEM bPtrPtr * *, * * cPtrPtr ITEM) {
ACurrent=aPtr ITEM * and * bCurrent=bPtr, * cCurrent=cPtr, * current=headPtr, * temp;
Char n;
Int flaga=0, flagb=0, flagc=0;//used to determine a, b, c if list is empty, empty it head pointer NULL
While (current) {
Temp=current;//record the current pointer
N=current - & gt; The data;//record the value of the current points to
The current=current - & gt; NextPtr;//the current point to the next list
If ((n>='a' & amp; & N<='z') | | (n>='A') & amp; & (n<='Z') & amp; & n!=' ') {
Temp - & gt; NextPtr=NULL;
ACurrent - & gt; NextPtr=temp;
ACurrent=temp;
Flaga=1;
}//determine whether for letters, behind it is it received a list
Else if (n>='0' & amp; & N<='9' & amp; & n!=' ') {
Temp - & gt; NextPtr=NULL;
BCurrent - & gt; NextPtr=temp;
BCurrent=temp;
Flagb=1;
}
Else if (n==' ')
continue;//if the space is skip
The else {
Temp - & gt; NextPtr=NULL;
CCurrent - & gt; NextPtr=temp;
CCurrent=temp;
Flagc=1;
}
}
If (flaga==0)
* aPtrPtr=NULL;
If (flagb==0)
* bPtrPtr=NULL;
If (flagc==0)
* cPtrPtr=NULL;//determine a, b, c for null
ACurrent=bCurrent=cCurrent=current=temp=NULL;
}
Void print (ITEM * headPtr) {
While (headPtr) {
Printf (" % c ", headPtr - & gt; The data);
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull