单原点最短路径算法与实现

更新时间:2023-06-11 01:16:01 阅读量: 实用文档 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

#include<>

#in cludeo struct link node

int data;

struct link node *next;

};

struct linknode *create( int n)〃创建单链表

{

int d;

j=O;

int i=l

z

struct linknode *head,*s,*t;

head=NULL;

printf("建立一个单链表:\n“);

printf("请输入数字:\n”);

printfC 嗷据%d:"z i);

scanf(”%cT,&d);

head=(struct link node *)malloc(sizeof(struct linkno de)); head->data=d;

/

head->n ext=NULL;

t=head; //建立第一个结点

for(j=l;j<=n;j++)//while(l)

{ i++;〃建立其余结点

printf("数据

scanf(”%d“,&d);

s=(struct lin knode *)malloc(sizeof(struct link no de));

s->data=d;

s->next=NULL;

t->n ext=s;

t=s;

if(i==n)

{

printf(”数据输入完毕!\n“);

break;

}

}

return head;

}

void disp(struct linknode *head)〃输出结点数据

struct link node *p=head; printfC ■输出一个单链表:\n“);

讦(p==NULL)

printf("空”);

while(p!=NULL)

{

printf(,,%d\n,,,p->data); p=p->n ext;

}

printfC'Xn");

}

struct link node *invert(struct link node *head) {

struct linknode *p,*q,*r; p=head;

q=p->n ext;

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 link node *head;

printf("输入数据个数n:\n");

scanf("%d”,&n);

while(n==O)

{printf(”输入有误:\n请重新输入数据个数:“); scanf(”%d“,&n);

} while( *=0)

{printf(“输入有误:\n请重新输入数据个数:”);

scanf(“%d”,&n);

}

head=create (n);

disp(head);

head=i nv ert(head);

disp(head);

本文来源:https://www.bwwdw.com/article/swx1.html

Top