线性表长度(线性表实训)

编写函数listLength函数来求线性表的长度。
函数listLength的函数原型为:
int listLength(node * h);
其中:

  1. 参数h为链表头指针;
  2. 返回值为链表长度。

温馨提示:这一关不难,遍历线性表,逐个对结点计数即可。

#include <iostream>
//#include "linearList.h"
using namespace std;
// 定义结点结构
struct node
{
   
    int data;  // 数据域
    node * next;  // 指针域,指向下一个结点
};
// 函数listLength:计算并返回链表的长度
// 参数:h-链表头指针
// 返回值:链表长度
int listLength(node * h);
// 函数delHas:删除链表中data为n的结点,如果有多个这样的结点,只删除第一个
// 参数:h-链表头指针,n-结点包含的数据
// 返回值:删除结束后链表首结点地址
node * delHas(node * h, int n);
// 函数delAt:删除链表中序号为i的结点,如果i是非法序号则不做操作
// 参数:h-链表头指针,i-要删除结点的序号
// 返回值:删除结束后链表首结点地址
node * delAt(node * h, int i);
// 函数search:在链表中查找包含数据num的结点
// 参数:h-链表头指针,num-要查找的数据
// 返回值:找到了返回该结点的地址,否则返回NULL
node * search(node * h, int num);
// 函数insertSort:链表排序插入
// 参数:h-链表头指针,t-指向要插入的结点
// 返回值:插入结点后链表的首结点地址
node * insertSort(node *h, node *t);
// 函数insertHead:链表头部插入
// 参数:h-链表头指针,t-指向要插入的结点
// 返回值:插入结点后链表的首结点地址
node * insertHead(node *h, node *t);
// 函数printList:输出链表,每个数据之间用一个空格隔开
// 参数:h-链表头指针
void printList(node *h);
// 函数insertTail:链表尾部插入
// 参数:h-链表头指针,t-指向要插入的结点
// 返回值:插入结点后链表的首结点地址
node *insertTail(node *h, node *t);
// 函数delList:删除链表,释放空间
// 参数:h-链表头指针
void delList(node *h);
int main()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

【执珪】瑕瑜·夕环玦

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

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

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

打赏作者

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

抵扣说明:

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

余额充值