标签:while class algo col turn amp code next def
#include<iostream> #include<stdio.h> #include<string.h> #include<algorithm> using namespace std; typedef struct Lnode { int data; Lnode *next; } Lnode,*linklist; void creat_back(linklist &a) { int n,tmp; linklist p,q; a=(linklist)malloc(sizeof(Lnode)); a->next=NULL; p=a; scanf("%d",&n); for (int i=0; i<n; i++) { scanf("%d",&tmp); q=(linklist)malloc(sizeof(Lnode)); q->data=tmp; q->next=NULL; p->next=q; p=q; } } void print(linklist a) { linklist p=a->next; while(p!=NULL) { printf("%d ",p->data); p=p->next; } printf("\n"); } void merge_ab(linklist aa,linklist bb,linklist &c) { linklist a=aa->next,b=bb->next; linklist p,q; c=(linklist)malloc(sizeof(Lnode)); c->next=NULL; p=c; while(a!=NULL && b!=NULL) { printf("%d %d\n",a->data,b->data); if (a->data < b->data) { q=(linklist)malloc(sizeof(Lnode)); q->data=a->data; q->next=NULL; p->next=q; p=q; a=a->next; } else { q=(linklist)malloc(sizeof(Lnode)); q->data=b->data; q->next=NULL; p->next=q; p=q; b=b->next; } } while(a!=NULL) { q=(linklist)malloc(sizeof(Lnode)); q->data=a->data; q->next=NULL; p->next=q; p=q; a=a->next; } while(b!=NULL) { q=(linklist)malloc(sizeof(Lnode)); q->data=a->data; q->next=NULL; p->next=q; p=q; b=b->next; } } int main() { linklist a,b,c; creat_back(a); print(a); creat_back(b); print(b); merge_ab(a,b,c); printf("zz"); print(c); return 0; }
标签:while class algo col turn amp code next def
原文地址:https://www.cnblogs.com/bluefly-hrbust/p/10187473.html