C++链表定义

来源:互联网 发布:avio.pw 新域名 编辑:程序博客网 时间:2024/06/05 18:25
// 结构体嵌套.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include "stdlib.h"#include #include using namespace std;struct teacher{int data;struct teacher *next;};teacher *creatlist(){teacher t1, t2, t3;teacher *p = NULL;//初始化t1.data = 1;t2.data = 2;t3.data = 3;t1.next = &t2;t2.next = &t3;t3.next = NULL;//静态链表p = &t1;//指针遍历链表while (p){printf("data:%d\n", p->data);p = p->next;}return &t1;}int main(){teacher *head = creatlist();system("pause"); return 0;}
0 0
原创粉丝点击