[c++]代码库
#include "stdafx.h"
#include <iostream>
using namespace std;
//C++静态链表
struct Book
{
int num;
int price;
Book *next;
};
//显示链表
void Show ( Book *head )
{
while ( head )
{
cout<<"编号为:"<<head->num<<",价格为:"<<head->price<<endl;
head=head->next;
}
}
int _tmain ( int argc, _TCHAR* argv[] )
{
Book *head=new Book;//头结点
Book *p1=new Book;
Book *p2=new Book;
Book *p3=new Book;
head->num=0;
head->price=0;
head->next=p1;
p1->num=1;
p1->price=10;
p1->next=p2;
p2->num=2;
p2->price=20;
p2->next=p3;
p3->num=3;
p3->price=30;
p3->next=NULL;
Show ( head );
system ( "pause" );
return 0;
}