静态链表:
#include<iostream> #include<string> using namespace std; struct book{ int num; float price; struct book *next; }; int main() { book x, y, z, *head, *p; x = {1,1.1f}; y = { 2, 2.2f }; z = { 3, 3.3f }; head = &x; x.next = &y; y.next = &z; z.next = NULL; p = head; while (p!=NULL) { cout << p->num<<‘\t‘<<p->price << endl; p = p->next; } return 0; }
时间: 2024-11-05 21:40:49