c ++ static list

Is a common list of important data structures. The simplest way linked list: a list head pointer variable head, which store an address. The address points to the first element. Each element of the list is called a node,

Each node comprises two parts: the first part with the actual user data, the second part of the address of the next node. This linked list data structure, must be achieved with structures and pointers.

#include <iostream>
using namespace std;
struct student
{
    int num;
    float score;
    struct student *next;
};

int main(){
    student a,b,c,*head,*p;
    a.num=31001;a.score=89.5;
    b.num=31003;b.score=90;
    c.num=31007;c.score=85;
    head = &a;
    a.next = &b;
    b.next = &c;
    c.next = NULL;
    p = head;
    do 
    {
        cout << p->num <<" "<< p->score<< endl;
        p = p->next;
    } while (p!=NULL);
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/overdo1949/p/11262890.html