#include "stdio.h"
#include"stdlib.h"
typedef struct Node
{
char data;
struct Node *next;
}Linklist;
Linklist *InitList(Linklist *L)
{
L = (Linklist *) malloc(sizeof(Linklist));
L->next = NULL;
return L;
}
Linklist *CreateList()
{
char x;
Linklist *L,*r,*p;
L = InitList(L);
r = L;
while(1)
{
scanf("%c",&x);
p = (Linklist *)malloc(sizeof(Linklist));
p -> data = x;
p -> next = NULL;
r->next = p;
r = r->next;
if( getchar()=='\n')
{
break;
}
}
return L;
}
void connect(Linklist *L,Linklist *S){
Linklist *p;
for(p=L;p->next!=NULL;p=p->next);
p->next = S->next;
}
void output(Linklist *L)
{
Linklist *p,*temp;
char t;
p = L->next;
for (temp = L->next; temp->next != NULL; temp = temp->next){
for (p = L->next; p->next != NULL; p = p->next){
if (p->data < p->next->data){
t = p->data;
p->data = p->next->data;
p->next->data = t;
}
}
}
p = L->next;
for(;p!=NULL;p=p->next)
{
printf("%c ",p->data);
}
printf("\n");
}
void put(Linklist *L)
{
Linklist *p;
p = L->next;
for(;p!=NULL;p=p->next)
{
printf("%d ",p->data);
}
printf("\n");
}
void change(Linklist *L,Linklist *S)
{
Linklist *p,*q,*tmp;
p = L->next->next;
q = S->next->next->next ;
tmp = S->next->next->next->next ;
q->next = L->next->next->next ;
L->next->next = q;
p->next = tmp ;
S->next->next->next= p;
}
ListMerge( Linklist *L1, Linklist *L2 ) {
Linklist *pa,*pb,*pc,*L;
L = (Linklist *)malloc(sizeof(struct Node));
pa = L1->next;
pb = L2->next;
pc = L;
while ( pa && pb ) {
if ( pa->data >= pb->data ) {
pc->next = pa;
pc = pa;
pa = pa->next;
} else {
pc->next = pb;
pc = pb;
pb = pb->next;
}
}
pc->next = pa ? pa : pb;
L1->next = NULL;
L2->next = NULL;
return L;
}
int main()
{
Linklist *L,*S,*Q;
L = CreateList();
S = CreateList();
output(L);
output(S);
Q = ListMerge(L,S);
output(Q);
}
楼
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...