博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
链表的操作 C/C++
阅读量:7088 次
发布时间:2019-06-28

本文共 2242 字,大约阅读时间需要 7 分钟。

一、创建链表,顺序增加数据,遍历链表操作

/** *C语言实现,用了三个指针操作,没用构造函数 */#include
using namespace std;struct student { int data; struct student* next;};int main(){ int data; struct student *head,*tail,*temp; head = NULL; while(cin>>data && data!=-1) { temp = (struct student*)malloc(sizeof(struct student)); temp->data = data; temp->next = NULL; if(head==NULL) { head = temp; tail = head; } else { tail->next = temp; tail = temp; } } tail = head; while(tail!=NULL) { cout<
data<
next; } system("pause"); return 0;}
/** *C/C++实现,用了三个指针操作,用了构造函数 */#include
using namespace std;struct student { int data; struct student* next; student(int a) { this->data = a; this->next = NULL; }};int main(){ int data; struct student *head,*tail,*temp; head = NULL; while(cin>>data && data!=-1) { if(head==NULL) { head = new student(data); tail = head; } else { temp = new student(data); //temp用来接收新节点,这样tail的next不会丢失 tail->next = temp; tail = temp; } } tail = head; while(tail!=NULL) { cout<
data<
next; } system("pause"); return 0;}
/** *C/C++实现,用了两个指针操作,用了构造函数 */#include
using namespace std;struct student { int data; struct student* next; student(int a) { this->data = a; this->next = NULL; } student(int a, struct student* p) { p->next = this; this->data = a; this->next = NULL; }};int main(){ int data; struct student *head,*tail; head = NULL; while(cin>>data && data!=-1) { if(head==NULL) { head = new student(data); tail = head; } else { tail = new student(data, tail); } } tail = head; while(tail != NULL) { cout<
data<
next; } system("pause"); return 0;}

二、(待续)

转载地址:http://xbfql.baihongyu.com/

你可能感兴趣的文章
VS2008 Project : error PRJ0019: 某个工具从以下位置返回了错误代码: "正在执行生成后事件..."解决方案...
查看>>
js判断图片是否存在,并做处理
查看>>
触摸屏
查看>>
webservice 测试窗体只能用于来自本地计算机的请求
查看>>
Java 中队列的使用
查看>>
再见 2014,你好 2015
查看>>
13 SELECT 以外的内容
查看>>
初中面谈招生网上招生报名系统
查看>>
.NET平台开源项目速览(9)软件序列号生成组件SoftwareProtector介绍与使用
查看>>
干货:史上最实用逃顶绝招十二式!
查看>>
鸟哥Linux私房菜 基础学习篇读书笔记(10):Linux磁盘和文件系统管理(3)
查看>>
简述Session 、Cookie、cache 区别
查看>>
large-scale analysis of malware downloaders
查看>>
pyqt声音输入
查看>>
FMX 模态窗体
查看>>
使用storyboard实现页面跳转,简单的数据传递
查看>>
有些事明显对自己有益,为什么却无法去做?
查看>>
IOS开发基础知识--碎片30
查看>>
C语言编程规范—命名规则
查看>>
批处理-剪切文件夹到指定目录
查看>>