你看这2个哪个符合你的要求我想了半天了,我不太会弄这个#include/*如发现bug请给我留言*/ #include#include#define LEN sizeof(struct node) struct node { char data; struct node *lchild,*rchild; }; struct node *build() { struct node *stack[20]={NULL},*root,*temp,*p; char c; int i=-1; c=getch(); if(c=='0') return NULL; root=p=(struct node *)malloc(LEN); p->data=c; c=getch(); while(1) { while(c!='0') { stack[++i]=p; p=(struct node *)malloc(LEN); p->data=c; stack->lchild=p; c=getch(); } p->lchild=NULL; c=getch(); while(c=='0'&&i>=0) { p->rchild=NULL; p=stack[i--]; c=getch(); } if(c!='0') { temp=(struct node *)malloc(LEN); p->rchild=temp; temp->data=c; p=temp; c=getch(); } else if(c=='0'&&ilchild!=NULL) { stack[++i]=p1; p1=p1->lchild; } printf("%c",p1->data); while(p1->rchild==NULL&&i>=0) { p1=stack[i--]; printf("%c",p1->data); } if(p1->rchild!=NULL) { p1=p1->rchild; } else if(p1->rchild==NULL&&i #include #define D 2 #define R 10 #define N 11 typedef int KeyType; typedef int DataType; struct Node; typedef struct Node radixNode; struct Node { KeyType key[D]; /* DataType info; */ radixNode *next; }; typedef radixNode * radixList; typedef struct QueueNode { radixNode *f; radixNode *e; } Queue; Queue queue[R]; void display(radixNode *plist) { int i; radixNode *p; p=plist->next; while(p!=NULL) { printf("->"); for(i=0;ikey); p=p->next; } printf("\n"); } void radixSort(radixNode *plist,int d,int r) { int i,j,k; radixNode *p,*head; head=plist->next; for(j=d-1;j>=0;j--) { p=head; for(i=0;ikey[j]; if(queue[k].f==NULL) queue[k].f=p; else (queue[k].e)->next=p; queue[k].e=p; p=p->next; } i=0; while(queue.f==NULL) i++; p=queue.e; head=queue.f; for(i++;inext=queue.f; p=queue.e; } p->next=NULL; printf("j=%d",j); } plist->next=head; } void main() { radixNode *p,*q,*head; int a[]={30,12,20,17,40,60,34,42,29,35,47}; int i; p=(radixNode *) malloc(sizeof(struct Node)); head=p; p->next=NULL; printf("test...\n"); for(i=0;ikey[0]=a/10; q->key[1]=a%10; q->next=NULL; p->next=q; p=p->next; } printf("before:\n"); display(head); printf("\n"); radixSort(head,D,R); printf("after:\n"); display(head); }
|