动态链表和静态链表
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
struct wep{
//char name[16];
int pwt;
float price;
struct wep *next;
};
/** 创建动态链表 **/
struct wep * create(){
struct wep *p1,*p2,*head;
int n = 0;
p1 = p2 = (struct wep*)malloc(sizeof(struct wep));
scanf("%d,%f",&p1->pwt,&p1->price);
head = NULL;
while(p1->pwt != 0){
n++;
if(n==1) head=p1;
else p2->next = p1;
p2 = p1;
p1 = (struct wep*)malloc(sizeof(struct wep));
scanf("%d,%f",&p1->pwt,&p1->price);
}
p2->next = NULL;
return head;
}
int main(void)
{
/*struct wep w_1 = {"shutdo",20,100.84};
struct wep warr[2] = {{"sh_1",30,122.99},{"sh_2",50,220.88}};
struct wep *w;
struct wep *w_arr;
w_arr = warr;
w = &w_1;
printf("%s -- %d ---- %.2f \n",w_1.name,w_1.pwt,w_1.price);
printf("%s -- %d ---- %.2f \n",(*w).name,(*w).pwt,(*w).price);
printf("%s -- %d ---- %.2f \n",w->name,w->pwt,w->price);
printf("%s -- %d ---- %.2f \n",w_arr->name,w_arr->pwt,w_arr->price);
printf("%p\n",w_arr);
w_arr++;
printf("%p\n",w_arr);
printf("%s -- %d ---- %.2f \n",w_arr->name,w_arr->pwt,w_arr->price);
printf("%u\n",sizeof(struct wep));*/
/**静态单向链表start***/
/*struct wep a,b,c,*head;
//a.name = {"tom"};
a.pwt = 18;
a.price = 19.8;
//b.name = {"jim"};
b.pwt = 20;
b.price = 122.88;
//c.name = {"lily"};
c.pwt = 77;
c.price = 19.99;
head = &a;
a.next = &b;
b.next = &c;
c.next = NULL;
struct wep *p;
p=head;
while(p!=NULL){
printf("-- %d -- %0.2f\n",(*p).pwt,(*p).price);
p = p->next;
}*/
/**静态单向链表end***/
struct wep *p;
p = create();
printf("%d-----%f\n",p->pwt,p->price);
return EXIT_SUCCESS;
}