单原点最短路径算法与实现(3 页)Good is good, but better carries it.精益求精,善益求善。#include#includestruct linknode{ int data; struct linknode *next;};struct linknode *create( int n)//创建单链表{ int d; int i=1,j=0; struct linknode *head,*s,*t; head=NULL; printf("建立一个单链表:\n"); printf("请输入数字:\n"); printf("数据%d:",i); scanf("%d",&d); head=(struct linknode *)malloc(sizeof(struct linknode)); head->data=d; head->next=NULL; t=head; //建立第一个结点 for(j=1;j<=n;j++)//while(1) { i++;//建立其余结点 printf("数据%d:",i); scanf("%d",&d); s=(struct linknode *)malloc(sizeof(struct linknode)); s->data=d; s->next=NULL; t->next=s; t=s; if(i==n) { printf("数据输入完毕!\n"); break; } } return head;}void disp(struct linknode *head)//输出结点数据{ struct linknode *p=head; printf("输出一个单链表:\n"); if(p==NULL) printf("空"); while(p!=NULL) { printf("%d\n",p->data); p=p->next; } printf("\n");}struct linknode *invert(struct linknode *head){ struct linknode *p,*q,*r; p=head; q=p->next; while(q!=NULL) { r=q->next; q->next=p; p=q; q=r; } head->next=NULL; head=p; return head;} void main(){ int n; struct linknode *head;printf("输入数据个数 n:\n");scanf("%d",&n);while(n==0){printf("输入有误:\n 请重新输入数据个数:");scanf("%d",&n);}while(n<=0){printf("输入有误:\n 请重新输入数据个数:");scanf("%d",&n);} head=create(n); disp(head); head=invert(head); disp(head);}(,、,@:——?>)@·'?}:~/`<》、~[~—|";