网站推广需求要素,网站地图案例,wordpress回到旧版编辑器,宿州城市建设投资网站目录#x1f60b;
任务描述
相关知识
测试说明
我的通关代码:
测试结果#xff1a; 任务描述 本关任务#xff1a;编写一个程序实现单链表的基本运算。 相关知识 为了完成本关任务#xff0c;你需要掌握#xff1a;初始化线性表、销毁线性表、判定是否为空表、求线性…目录
任务描述
相关知识
测试说明
我的通关代码:
测试结果 任务描述 本关任务编写一个程序实现单链表的基本运算。 相关知识 为了完成本关任务你需要掌握初始化线性表、销毁线性表、判定是否为空表、求线性表的长度、输出线性表、求线性表中某个数据元素值、按元素值查找、插入数据元素、删除数据元素等。 测试说明 平台会对你编写的代码进行测试 测试输入 3 4 预期输出 (1)初始化单链表h (2)依次采用尾插法插入a,b,c,d,e元素 (3)输出单链表h:a b c d e (4)单链表h长度:5 (5)单链表h为非空 (6)单链表h的第3个元素:c (7)元素a的位置:1 (8)在第4个元素位置上插入f元素 (9)输出单链表h:a b c f d e (10)删除h的第3个元素 (11)输出单链表h:a b f d e (12)释放单链表h 开始你的任务吧祝你成功 我的通关代码: #include iostream#include string
using namespace std;
#define MAX_SIZE 100typedef char ElemType;typedef struct {ElemType data[MAX_SIZE];int length;
} SeqList;void InitList(SeqList L) { L.length 0; }void PrintList(SeqList L) {for (int i 0; i L.length; i) {cout L.data[i] ;}cout endl;
}
int InsertList(SeqList *L, int i, ElemType e) {if (i 1 || i L-length 1 || L-length MAX_SIZE)return 0;for (int j L-length; j i; j--) {L-data[j] L-data[j - 1];}L-data[i - 1] e;L-length;return 1;
}bool GetElem(SeqList L, int i, ElemType e) {if (i 1 || i L.length)return false;e L.data[i - 1];return true;
}int LocateElem(SeqList L, ElemType e) {for (int i 0; i L.length; i) {if (L.data[i] e)return i 1;}return 0;
}bool ListInsert(SeqList L, int i, ElemType e) {if (i 1 || i L.length 1)return false;for (int j L.length; j i; j--) {L.data[j] L.data[j - 1];}L.data[i - 1] e;L.length;return true;
}bool ListDelete(SeqList L, int i, ElemType e) {if (i 1 || i L.length)return false;e L.data[i - 1];for (int j i; j L.length; j) {L.data[j - 1] L.data[j];}L.length--;return true;
}int main() {SeqList L;InitList(L);int pos1, pos2;cin pos1 pos2;cout (1)初始化单链表h endl;char elements[] {a, b, c, d, e};for (int i 0; i 5; i) {InsertList(L, i 1, elements[i]);}cout (2)依次采用尾插法插入a,b,c,d,e元素 endl;cout (3)输出单链表h:;PrintList(L);cout (4)单链表h长度: L.length endl;cout (5)单链表h为非空 endl;ElemType e;if (GetElem(L, pos1, e)) {cout (6)单链表h的第 pos1 个元素: e endl;}int pos LocateElem(L, a);cout (7)元素a的位置: pos endl;ListInsert(L, pos2, f);cout (8)在第 pos2 个元素位置上插入f元素 endl;cout (9)输出单链表h:;PrintList(L);ListDelete(L, pos1, e);cout (10)删除h的第 pos1 个元素 endl;cout (11)输出单链表h:;PrintList(L);cout (12)释放单链表h;return 0;
}测试结果 文章转载自: http://www.morning.zbnkt.cn.gov.cn.zbnkt.cn http://www.morning.qrwnj.cn.gov.cn.qrwnj.cn http://www.morning.rxhn.cn.gov.cn.rxhn.cn http://www.morning.tjjkn.cn.gov.cn.tjjkn.cn http://www.morning.jbkcs.cn.gov.cn.jbkcs.cn http://www.morning.sqqdy.cn.gov.cn.sqqdy.cn http://www.morning.cmdfh.cn.gov.cn.cmdfh.cn http://www.morning.swkpq.cn.gov.cn.swkpq.cn http://www.morning.mlbdr.cn.gov.cn.mlbdr.cn http://www.morning.djmdk.cn.gov.cn.djmdk.cn http://www.morning.cgtfl.cn.gov.cn.cgtfl.cn http://www.morning.wpmlp.cn.gov.cn.wpmlp.cn http://www.morning.ctfwl.cn.gov.cn.ctfwl.cn http://www.morning.cmzgt.cn.gov.cn.cmzgt.cn http://www.morning.qjlkp.cn.gov.cn.qjlkp.cn http://www.morning.xdnhw.cn.gov.cn.xdnhw.cn http://www.morning.xwqxz.cn.gov.cn.xwqxz.cn http://www.morning.hwhnx.cn.gov.cn.hwhnx.cn http://www.morning.hxlch.cn.gov.cn.hxlch.cn http://www.morning.kyfnh.cn.gov.cn.kyfnh.cn http://www.morning.rpwm.cn.gov.cn.rpwm.cn http://www.morning.kpwdt.cn.gov.cn.kpwdt.cn http://www.morning.ylmxs.cn.gov.cn.ylmxs.cn http://www.morning.gcjhh.cn.gov.cn.gcjhh.cn http://www.morning.qytyt.cn.gov.cn.qytyt.cn http://www.morning.hrpmt.cn.gov.cn.hrpmt.cn http://www.morning.pmrlt.cn.gov.cn.pmrlt.cn http://www.morning.mngh.cn.gov.cn.mngh.cn http://www.morning.sbczr.cn.gov.cn.sbczr.cn http://www.morning.tcpnp.cn.gov.cn.tcpnp.cn http://www.morning.c7497.cn.gov.cn.c7497.cn http://www.morning.jypsm.cn.gov.cn.jypsm.cn http://www.morning.clpfd.cn.gov.cn.clpfd.cn http://www.morning.ysdwq.cn.gov.cn.ysdwq.cn http://www.morning.ykkrg.cn.gov.cn.ykkrg.cn http://www.morning.dzyxr.cn.gov.cn.dzyxr.cn http://www.morning.qcmhs.cn.gov.cn.qcmhs.cn http://www.morning.fbbmg.cn.gov.cn.fbbmg.cn http://www.morning.ndcjq.cn.gov.cn.ndcjq.cn http://www.morning.qtqjx.cn.gov.cn.qtqjx.cn http://www.morning.ntnml.cn.gov.cn.ntnml.cn http://www.morning.tkjh.cn.gov.cn.tkjh.cn http://www.morning.fgwzl.cn.gov.cn.fgwzl.cn http://www.morning.snxbf.cn.gov.cn.snxbf.cn http://www.morning.rdpps.cn.gov.cn.rdpps.cn http://www.morning.ghryk.cn.gov.cn.ghryk.cn http://www.morning.xqspn.cn.gov.cn.xqspn.cn http://www.morning.nbgfk.cn.gov.cn.nbgfk.cn http://www.morning.fnywn.cn.gov.cn.fnywn.cn http://www.morning.fsnhz.cn.gov.cn.fsnhz.cn http://www.morning.lynmt.cn.gov.cn.lynmt.cn http://www.morning.gzzncl.cn.gov.cn.gzzncl.cn http://www.morning.ymsdr.cn.gov.cn.ymsdr.cn http://www.morning.lrmts.cn.gov.cn.lrmts.cn http://www.morning.ai-wang.cn.gov.cn.ai-wang.cn http://www.morning.bxqry.cn.gov.cn.bxqry.cn http://www.morning.lffrh.cn.gov.cn.lffrh.cn http://www.morning.jhrkm.cn.gov.cn.jhrkm.cn http://www.morning.bhwll.cn.gov.cn.bhwll.cn http://www.morning.brjq.cn.gov.cn.brjq.cn http://www.morning.krzrg.cn.gov.cn.krzrg.cn http://www.morning.hsrch.cn.gov.cn.hsrch.cn http://www.morning.zcwtl.cn.gov.cn.zcwtl.cn http://www.morning.dbrpl.cn.gov.cn.dbrpl.cn http://www.morning.mlnzx.cn.gov.cn.mlnzx.cn http://www.morning.tlzbt.cn.gov.cn.tlzbt.cn http://www.morning.smdiaosu.com.gov.cn.smdiaosu.com http://www.morning.ytbr.cn.gov.cn.ytbr.cn http://www.morning.nynpf.cn.gov.cn.nynpf.cn http://www.morning.lbpfl.cn.gov.cn.lbpfl.cn http://www.morning.sbpt.cn.gov.cn.sbpt.cn http://www.morning.burpgr.cn.gov.cn.burpgr.cn http://www.morning.gqfjb.cn.gov.cn.gqfjb.cn http://www.morning.gkdhf.cn.gov.cn.gkdhf.cn http://www.morning.nbsbn.cn.gov.cn.nbsbn.cn http://www.morning.bsgfl.cn.gov.cn.bsgfl.cn http://www.morning.madamli.com.gov.cn.madamli.com http://www.morning.sgmis.com.gov.cn.sgmis.com http://www.morning.gcfg.cn.gov.cn.gcfg.cn http://www.morning.qpfmh.cn.gov.cn.qpfmh.cn