【文件属性】:
文件名称:链表制作ssss
文件大小:21KB
文件格式:DOC
更新时间:2016-02-02 09:15:20
linklist
#include
#include
#include
struct Road
{
int name;
float WE_start;
float NS_start;
float WE_end;
float NS_end;
float flowrate;
int width;
int length;
struct Road *next;
}road[50];
typedef struct Road ElemType;
struct LNODE
{
ElemType data;
struct LNODE *next;
};
typedef struct LNODE LNode;
typedef struct LNODE *LinkList;
int init(LinkList *L)
{
*L=(LNode *)malloc(sizeof(LNode));
if(!L)
exit(-1);
memset(&((*L)->data),0,sizeof(struct Road));
(*L)->next=NULL;
return 1;
}
int ListInsert(LinkList L,int i,ElemType e)
{
LinkList p,s;
int j;
p=L;j=0;
while(p&&(j<(i-1)))
{
p=p->next;
++j;
}
if(!p||(j>(i-1)))
return 0;
s=(LinkList)malloc(sizeof(LNode));
s->data=e;
s->next=p->next;
p->next=s;
return 1;
}
int printlist(LinkList L)
{
int i;
LinkList p;
p=L;
printf("name WE_start NS_start WE_end NS_end flowrate width length\n");
while(p->next)
{
p=p->next;
printf("%-10s%d\t%d\t%d\t%d\t%d\t%d\t%d\t",p->data.name,p->data.WE_start,p->data.NS_start,p->data.WE_end,p->data.NS_end,p->data.flowrate,p->data.width,p->data.length);
}
printf("\n");
}
int main()
{
struct Road e;
LinkList La ;
init(&La;);
e.name=1;
e.WE_start=11;
e.NS_start=12;
e.WE_end=23;
e.NS_end=33;
e.flowrate=1;
e.width=2;
e.length=3;
ListInsert(La,1,e);
printlist(La);
getchar();
}