码迷,mamicode.com
首页 > 其他好文 > 详细

数据结构线性表111

时间:2019-03-25 23:15:13      阅读:191      评论:0      收藏:0      [点我收藏+]

标签:link   als   4行   理解   turn   data   意思   maxsize   element   

1.代码简介:

将X插入在位置P并返回true。若空间已满,则打印“FULL”并返回false;如果参数P指向非法位置,则打印“ILLEGAL POSITION”并返回false;

1.1. 代码:

bool Insert( List L, ElementType X, Position P )
{
if(!L)return false;  //1
if(L->Last==MAXSIZE){  //2
printf("FULL");return false;  //3
} if(P<0||P>L->Last){  //4
printf("ILLEGAL POSITION");return false;  //5
}

for(int i=L->Last;i>P;i--){   //6
L->Data[i]=L->Data[i-1];  //7
}L->Data[P]=X;  //8
++L->Last;       //9
return true;  //10
}

2.不懂的地方

第6行到第9行:++L->Last不懂是什么意思。理解不了这段代码的功能

2.代码简介

1.1.代码:

void Insert_Linklist(LinkList& p,int pos,char e){
if(pos<=0||Get_Length(p)<pos-1)return;  //1
int cnt=2;  //2
LinkList head=p->next,t;  //3
while(head!=p){  //4
if(cnt==pos){  //5
t=(LinkList)malloc(sizeof(LNode));  //6
t->data=e;  //7
t->next=head->next;  //8
head->next=t;  //9
}
cnt++;  //10
head=head->next;  //11
}

2.不懂的地方

第4行到第9行:t=(LinkList)malloc(sizeof(LNode))这段代码有什么用途。

数据结构线性表111

标签:link   als   4行   理解   turn   data   意思   maxsize   element   

原文地址:https://www.cnblogs.com/JianDa/p/10597344.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!