C++双链表各项操作(含代码)

C++实现数据结构的双链表,写的不好,学习数据结构可以参考。
摘要由CSDN通过智能技术生成

C++双链表各项操作(含代码)

目录

功能描述

  • 双链表的初始化
  • 头插法插入信息
  • 尾插法插入信息
  • 按照序号查找节点信息
  • 按照信息查找(此处为按照学号查找)
  • 插入结点操作,把目标信息插入到第i个结点
  • 删除第i个数据
  • 显示当前信息函数show(内置于各个操作中)
  • 求当前链表长度函数length(内置于各个操作中)

代码实现

#include<iostream>
#define OVERFLOE -2
#define ERROR -1
#define OK 1
using namespace std;

//定义一个数据结构
typedef struct {
   
	int no;
	string name;
	int score;
}elemType;
typedef struct Dnode{
   
	elemType data;
	struct Dnode* next;
	struct Dnode* prior;
}Dnode,*DLinkList;

//初始化一个双链表
int initDLinkList(DLinkList& l) {
   
	l = new Dnode;
	if (l != NULL)
	{
   
		l->next = NULL;
		l->prior = NULL;
		return OK;
	}
	else
		return ERROR;
}
//双链表的头插法
DLinkList creatDLinkList1(DLinkList& l) {
   
	Dnode* node; elemType e;
	if (l != NULL)
		initDLinkList(l);
	cout << "输入学号,姓名,分数:"; cin >> e.no >> e.name >> e.score;
	while (e.no != 000) {
   
		node = new Dnode;
		node->data = e;
		node->next = l->next;
		if(l->next != NULL)
			l->next->prior = node;
		node->prior = l;
		l->next = node;
		cout << "输入学号,姓名,分数:"; cin >> e.no >> e.name >> e.score;
	}
	return l;
}

//双链表的尾插法
DLinkList creatDLinkList2(DLinkList& l)
{
   
	if (l != NU
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Mr.Oner

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值