链表

#include <stdlib.h>

using namespace std;

struct Student {

long num;

float score;

struct Student *next;

};

int n=0;

struct Student *create(void) {

struct Student *head;

struct Student *p;

struct Student *tail;

head=NULL;

p=(struct Student *)malloc(sizeof(struct Student));

cin>>p->num>>p->score;

while(p->num != 0) {

if(head == NULL)

head=p;

else

tail->next=p;

tail=p;

p=(struct Student *)malloc(sizeof(struct Student));

cin>>p->num>>p->score;

}

tail->next=NULL;

return head;

}

int main(int argc, char *argv[]) {

struct Student *head=create();

struct Student *p=head;

while(p != NULL) {

cout<<"node[num = "<num<<", score = "<score<<endl;

p=p->next;

}

system("PAUSE");

return EXIT_SUCCESS;

}

你可能感兴趣的:(链表)