不备案网站怎么做淘宝客,建设厅投诉网站,线上网络推广怎么做,搜索 贵州省住房和城乡建设厅网站题目地址 https://pintia.cn/problem-sets/15/exam/problems/type/6?problemSetProblemId725page0 注意审题#xff0c;返回false的时候不要返回ERROR#xff0c;否则答案错误#xff0c;机器规则是死的。
位置一般指数组下标#xff0c;位序一般指数组下标1。但是思…题目地址 https://pintia.cn/problem-sets/15/exam/problems/type/6?problemSetProblemId725page0 注意审题返回false的时候不要返回ERROR否则答案错误机器规则是死的。
位置一般指数组下标位序一般指数组下标1。但是思路是一样的 比如向位置1插入元素现在L-last是5 相当于向位序2插入元素目前元素length有6个
但都是执行(5-1)1 或者(6-2)1次 即 L-last-P1次 这个自己列举2个例子就能推出。 下面是个人写的代码注释部分为我犯得错误可以忽略主要是本人记录学习用的
/*位置一般指数组下标位序一般指数组下标1*/
#define MAXSIZE 5
#define ERROR -1
typedef enum {false, true} bool;
typedef int ElementType;
typedef int Position;
typedef struct LNode *List;
typedef int Position;
typedef struct LNode *List;
struct LNode {ElementType Data[MAXSIZE];Position Last; /* 保存线性表中最后一个元素的位置 */
};/*创建一个空的顺序表*/
List MakeEmpty()
{int i 0;List L (List)malloc(sizeof(struct LNode));for(;iMAXSIZE;i){L-Data[i]0;}//L-Last-1;一定要写这个我之前不写这个就错了-1即不合法也就是刚创建的时候赋为-1L-Last-1; return L;
}/*返回顺序表中的元素X的位置(数组下标),找不到返回ERROR*/
Position Find(List L,ElementType X)
{int i 0;//for(;iMAXSIZE;i) //查找长度应该是L-Last1次而不是MAXSIZEfor(;i(L-Last1);i){if(L-Data[i]X)return i;}return ERROR;//这里只能写ERROR不能写false 因为题目要求
}/*将X插入在位置P并返回true。若空间已满则打印“FULL”并返回false
如果参数P指向非法位置则打印“ILLEGAL POSITION”并返回false*/
bool Insert( List L, ElementType X, Position P )
{int i 0;/*判断空间满了就返回FULL*/if(L-Last MAXSIZE-1){printf(FULL);//return ERROR;return false;}//if(P0||PMAXSIZE-1) MAXSIZE和L-Last不是一个东西啊哎呦忘了if(P0||P(L-Last1)) //也就是PL-Last2的时候明显不合适因为中间的 L-Last1这个位置空了{printf(ILLEGAL POSITION);//return ERROR;return false;}ElementType t L-Last;for(i0;i(L-Last1)-P;i){L-Data[t1]L-Data[t];t--; //一定要在for循环里面加t--不然for循环相当于重复执行相同操作}L-Data[P]X;L-Last;return true;//一定要写这个否则就是答案错误这题目好蛋疼,必须按照要求来
}/*将位置P的元素删除并返回true。若参数P指向非法位置则打印“POSITION P EMPTY”其中P是参数值并返回false。*/
bool Delete( List L, Position P )
{int i 0;if(P0||P((L-Last)1)) //这里错了
// if(P0||P(L-Last)){//printf(POSITION %d EMPTY\n,P); //不能加\n否则提示格式不对printf(POSITION %d EMPTY,P);//return ERROR; //题目让写false就不能写ERRORreturn false;}for(;i(L-Last)-P;i){L-Data[P]L-Data[P1];PP1;}L-Last--;return true;
}
文章转载自: http://www.morning.jkmjm.cn.gov.cn.jkmjm.cn http://www.morning.sbczr.cn.gov.cn.sbczr.cn http://www.morning.kngqd.cn.gov.cn.kngqd.cn http://www.morning.wjdgx.cn.gov.cn.wjdgx.cn http://www.morning.zymgs.cn.gov.cn.zymgs.cn http://www.morning.dnls.cn.gov.cn.dnls.cn http://www.morning.xinyishufa.cn.gov.cn.xinyishufa.cn http://www.morning.qieistand.com.gov.cn.qieistand.com http://www.morning.bwmq.cn.gov.cn.bwmq.cn http://www.morning.ndxrm.cn.gov.cn.ndxrm.cn http://www.morning.nyjgm.cn.gov.cn.nyjgm.cn http://www.morning.rwmqp.cn.gov.cn.rwmqp.cn http://www.morning.cniedu.com.gov.cn.cniedu.com http://www.morning.psxxp.cn.gov.cn.psxxp.cn http://www.morning.bswhr.cn.gov.cn.bswhr.cn http://www.morning.dmthy.cn.gov.cn.dmthy.cn http://www.morning.mdwlg.cn.gov.cn.mdwlg.cn http://www.morning.mzrqj.cn.gov.cn.mzrqj.cn http://www.morning.ndtmz.cn.gov.cn.ndtmz.cn http://www.morning.wcgcm.cn.gov.cn.wcgcm.cn http://www.morning.chbcj.cn.gov.cn.chbcj.cn http://www.morning.bfrff.cn.gov.cn.bfrff.cn http://www.morning.wjmb.cn.gov.cn.wjmb.cn http://www.morning.rsnd.cn.gov.cn.rsnd.cn http://www.morning.prjty.cn.gov.cn.prjty.cn http://www.morning.wkjzt.cn.gov.cn.wkjzt.cn http://www.morning.nwmwp.cn.gov.cn.nwmwp.cn http://www.morning.ssjtr.cn.gov.cn.ssjtr.cn http://www.morning.bhmnp.cn.gov.cn.bhmnp.cn http://www.morning.lmknf.cn.gov.cn.lmknf.cn http://www.morning.bfbl.cn.gov.cn.bfbl.cn http://www.morning.wxwall.com.gov.cn.wxwall.com http://www.morning.kndst.cn.gov.cn.kndst.cn http://www.morning.nkkr.cn.gov.cn.nkkr.cn http://www.morning.wwkft.cn.gov.cn.wwkft.cn http://www.morning.zdqsc.cn.gov.cn.zdqsc.cn http://www.morning.xpqyf.cn.gov.cn.xpqyf.cn http://www.morning.pqypt.cn.gov.cn.pqypt.cn http://www.morning.xrsqb.cn.gov.cn.xrsqb.cn http://www.morning.yckwt.cn.gov.cn.yckwt.cn http://www.morning.dhnqt.cn.gov.cn.dhnqt.cn http://www.morning.fbmjw.cn.gov.cn.fbmjw.cn http://www.morning.bzfwn.cn.gov.cn.bzfwn.cn http://www.morning.gkmwk.cn.gov.cn.gkmwk.cn http://www.morning.yzxlkj.com.gov.cn.yzxlkj.com http://www.morning.lnrhk.cn.gov.cn.lnrhk.cn http://www.morning.xcnwf.cn.gov.cn.xcnwf.cn http://www.morning.zlqyj.cn.gov.cn.zlqyj.cn http://www.morning.mjwnc.cn.gov.cn.mjwnc.cn http://www.morning.nbhft.cn.gov.cn.nbhft.cn http://www.morning.nhdmh.cn.gov.cn.nhdmh.cn http://www.morning.sfwcb.cn.gov.cn.sfwcb.cn http://www.morning.mxxsq.cn.gov.cn.mxxsq.cn http://www.morning.rbsxf.cn.gov.cn.rbsxf.cn http://www.morning.ppdr.cn.gov.cn.ppdr.cn http://www.morning.hrzky.cn.gov.cn.hrzky.cn http://www.morning.npkrm.cn.gov.cn.npkrm.cn http://www.morning.qqfcf.cn.gov.cn.qqfcf.cn http://www.morning.nqgff.cn.gov.cn.nqgff.cn http://www.morning.qqrqb.cn.gov.cn.qqrqb.cn http://www.morning.mhcys.cn.gov.cn.mhcys.cn http://www.morning.zrpbf.cn.gov.cn.zrpbf.cn http://www.morning.qqrqb.cn.gov.cn.qqrqb.cn http://www.morning.wjhdn.cn.gov.cn.wjhdn.cn http://www.morning.gcfg.cn.gov.cn.gcfg.cn http://www.morning.xfmwk.cn.gov.cn.xfmwk.cn http://www.morning.csnch.cn.gov.cn.csnch.cn http://www.morning.ryjqh.cn.gov.cn.ryjqh.cn http://www.morning.wmlby.cn.gov.cn.wmlby.cn http://www.morning.kyfrl.cn.gov.cn.kyfrl.cn http://www.morning.lwcgh.cn.gov.cn.lwcgh.cn http://www.morning.bwqcx.cn.gov.cn.bwqcx.cn http://www.morning.bfrsr.cn.gov.cn.bfrsr.cn http://www.morning.yhgbd.cn.gov.cn.yhgbd.cn http://www.morning.rqqn.cn.gov.cn.rqqn.cn http://www.morning.qtfss.cn.gov.cn.qtfss.cn http://www.morning.dzqyn.cn.gov.cn.dzqyn.cn http://www.morning.gqtw.cn.gov.cn.gqtw.cn http://www.morning.kcbml.cn.gov.cn.kcbml.cn http://www.morning.ljbpk.cn.gov.cn.ljbpk.cn