结构体链表

#include <IOSTREAM>
using namespace std;
struct book //class
{
int num;
float price;
struct book*next;//type+type_name+pointer
};
int main()
{
book x,y,z,*head,*p;
x.num=10000;
x.price=14.5;
y.num=15000;
y.price=15.5;
z.num=20000;
z.price=16.5;
head=&x;//define x the head node
x.next=&y;
y.next=&z;
z.next=NULL;//the end of link
p=head;
for(int i=0;i<3;i++)
{
cout<<p->num<<endl;
cout<<p->price<<endl;
p--;
}
return 0;
}

posted on 2012-12-17 16:04  Jerold  阅读(123)  评论(0)    收藏  举报

导航