?? xxbgb.cpp
字號:
#include<stdio.h>
#include<malloc.h>
typedef struct node{
int data;
struct node * next;
}Lnode;
Lnode * create(int tag)//用前插法建立單鏈表
{
Lnode *p,*h=NULL;
int x;
printf("請輸入元素值(數字):");
scanf("%d" ,&x);
while(x!=tag)
{
p=(Lnode *)malloc(sizeof(Lnode));
p->data =x;
p->next=h;
h=p;
scanf("%d",&x);
}
return h;
}
void printd(Lnode *h)//打印單鏈表中的一個節點的數據域值
{
while(h!=NULL)
{printf("%3d",h->data);
h=h->next;}
printf("\n");
}
Lnode *mergeab(Lnode *ha, Lnode *hb)//歸并單鏈表
{
Lnode *p,*q,*r,*head=(Lnode*)malloc(sizeof(Lnode));
head->next=hb;
while(ha){
p=ha;ha=p->next;
r=head;hb=head->next;
while(hb){
if(p->data<hb->data){
r->next=p;
p->next=hb;break;}
else
if(p->data==hb->data)
free(p);
else{
r=hb;hb=r->next;}
}
}
hb=head->next;
free(head);
return hb;
}
main()
{
Lnode *ha,*hb;
int tag=0;
printf("輸入完成后請敲擊回車后以0結束\n");
printf("------------------------------------\n");
printf(" 請輸入ha 中元素:\n");
ha=create(tag);
printf("ha中的元素為:") ;
printd(ha);
printf("------------------------------------\n");
printf("輸入hb 中元素:\n");
hb=create(tag);
printf("ha中的元素為:") ;
printd(hb);
hb=mergeab(ha,hb);printf("------------------------------------\n");
printf("歸并后的數字為:");
printd(ha);
getchar();getchar();
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -