C语言 c++ php mysql nginx linux lnmp lamp lanmp memcache redis 面试 笔记 ppt 设计模式 问题 远程连接

c++学习-链表

 

静态链表:

#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;
}

 

posted on 2015-06-28 12:55  思齐_  阅读(249)  评论(0编辑  收藏  举报