C++实现线性表(链表描述)

本文使用C++实现了一个线性表(数组描述)。该程序由三个文件构成,第一部分是头文件,头文件定义了一个链表的节点的结构体,同时在该结构体的基础上定义了一个线性表类,该抽象类中定义了绝大部分线性表的成员函数,其中包括:

  1. 确定线性表是否为空
  2. 确定线性表中数据的数目
  3. 添加一个数据
  4. 按一个给定索引查找其对应的元素
  5. 按数据删除一个节点
  6. 遍历输出(反向输出)该线性表
  7. 格式化该线性表
  8. 排序(反向排序)该线性表
    第二部分是测试代码。整个程序使用Xcode编译。其中,头文件源码如下:
//
//  Node_List.hpp
//  node_list
//
//  Created by lq on 2019/9/2.
//  Copyright © 2019 Mr.liang. All rights reserved.
//

#ifndef Node_List_hpp
#define Node_List_hpp
#include <iostream>
using namespace std;
struct node
{
    node* next;
    node* last;
    int data;
};

class node_chain
{
private:
    node* head;
    node* tail;
    int length;
public:
    node_chain()
    {
        head = new node;
        tail = new node;
        head->next = tail;
        head->last = nullptr;
        tail->next = nullptr;
        tail->last = head;
        length = 0;
    }
    node_chain(const node_chain &s)
    {
        head = new node;
        tail = new node;
        head->next = tail;
        head->last = nullptr;
        tail->last = head;
        length = 0;
        node* temp = s.head;
        while(temp->next != s.tail)
        {
            temp = 
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值