Problem: Two strings that are known to be stored separately with two single linked lists are sorted in ascending order. The programming implementation merges these two single linked lists into a single linked list in descending order of data field values.
Requirements:
1 Each node in a single linked list holds only one character
2) use the node space in the original linked list to store the merged single linked list, not to generate a new list
3. Create a function Create implementation
4) Two list merge process write one function sub implement
5) output result write one function outputs implementation
6 The main function calls these three functions to complete the program function
#include <stdio.h> #include <string.h> #include <stdlib.h> #define LEN sizeof (struct str) struct STR {
char s;
struct STR *next;
};
typedef struct STR str;
Str *creat (char *string) {str *head=null;
STR *prev,*current;
Char *p=string;
while (* (string)!= ' I ') {current= (STR *) malloc (LEN);
if (head==null) head=current;
else prev->next=current;
current->s=* (string);
string++;
current->next=null;
Prev=current;
return head;
} void Output (str *head) {str * P=HEAD;
printf ("The string is:\n");
if (head!=null) do {printf ("%c", p->s);
p=p->next;
}while (P!=null);
} void sub (str *a,str *b) {str *p1,*p2,*q;
char temp;
P1=a;p2=b;
while (P1->next) {p1=p1->next;
} p1->next=p2;
P1=a; while (P1->next) {q=p1->Next
while (q) {if (q->s<p1->s) {temp=q->s;
q->s=p1->s;
p1->s=temp;
} q=q->next;
} p1=p1->next;
int main () {char a[]= ' I am a student! ';
Char b[]= "Where are you form?";
STR *P1,*P2;
P1=creat (a);
P2=creat (b);
Sub (P1,P2);
Output (p1);
Putchar (' \ n ');
Output (p2);
Putchar (' \ n ');
}