我在for循环中有一些问题,我还没有看到像这样的code'style [英] I have some question in for loop and I haven't seen code'style like this

查看:68
本文介绍了我在for循环中有一些问题,我还没有看到像这样的code'style的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码用于创建班轮列表

My code is used for creating a liner list

我是学生,所以我遇到了一些问题

I'm a student ,so I have some problems

这是代码。

如果太长时间阅读,你可以看到这个

if it's too long too read ,you can see this

         ; int * q;

         int *q;

   ;    p> = q; --p)*(p + 1)= * p;                  
/ *" - p)"为什么&NBSP?;不要成为"( - p)"? 如何使用它? * /

     p >= q; --p)*(p + 1) = *p;                   /* "--p)" why?  Shoudn't be "(--p)"?  How to use it? */

------------- -------------------------------------------------- ----------------------------------------

-------------------------------------------------------------------------------------------------------

typedef
int
状态 ;

typedef int Status;

typedef
struct
LineList

{

int * elem;

int*elem;

int
length;

int length;

int
Listsize;

int Listsize;

} 列表 ;

}List;

状态
IntLineList( 列表 * L

Status IntLineList (List*L)

{

L - > elem
=(
int *)malloc( List_INIT_SIZE *
sizeof int ));

L->elem = (int*)malloc(List_INIT_SIZE* sizeof(int));

if (! L - > elem)

if(!L->elem)

返回
OVERFLOW ;

return OVERFLOW;

L - > length
= 0;

L->length = 0;

L - > Listsize
=
List_INIT_SIZE ;

L->Listsize = List_INIT_SIZE;

printf( "衬垫列表已成功创建
!\ n"
);

printf ("Liner List has been created succesfully !\n");

return O K ;

return OK;

}

状态
ListInsert( 列表 * L int
I < span style ="font-size:small"> int
e

Status ListInsert (List*L,int i,int e)

{

如果
i < 1
||
i > L - > ;长度
+ 1)

if (i<1 || i>L->length + 1)

{

printf( "错误的插入位置!\ n" );

printf ("Wrong Insert Place!\n");

返回
ERROR ;

return ERROR;

}

如果
L - > length
> =
L - > Listsize)

if (L->length >= L->Listsize)

{

int
* newbase =( int *) realloc( L - > ; elem,
L - > Listsize +
LISTINCREAMENT )*
sizeof int ));

int *newbase= (int*)realloc(L->elem, (L->Listsize + LISTINCREAMENT) * sizeof(int));

< span style ="font-size:small"> 如果
(! newbase)

if (!newbase)

{

printf( " ERROR!" );

printf ("ERROR!");

返回
ERROR ;

return ERROR;

}

L - > elem
= newbase;

L->elem = newbase;

L - > Listsize
+ =
LISTINCREAMENT ;

L->Listsize += LISTINCREAMENT;

}

int
* q =&( L - > elem [ i -
1]);

int *q=&(L->elem[i- 1]);

for

int * p =&( L - > elem [ L - >长度
- 1]);     / * for循环可以像这样使用??? * /

for ( int*p = &(L->elem[L->length - 1]);     /*for loop can be used like this ???*/

p> = q; --p)*(p + 1)= * p;                  
/ *" - p)"为什么?以及如何使用? * /

p >= q; --p)*(p + 1) = *p;                   /* "--p)" why? and How to use? */

< span style ="font-size:small"> * q = e ;

*q = e;

++ L - > length;

++L->length;

printf( < span style ="color:#a31515; font-size:small"> " Insert Success!\ n" );

printf ("Insert Success! \n");

返回
确定 ;

return OK;

}

推荐答案

On 5/16/2017 10:54 AM,Beyond Dark写道:

On 5/16/2017 10:54 AM, Beyond Dark wrote:


for(int * p =&(L-> elem [L-> length - 1]);    for循环可以像这样使用???

p> = q; --p)*( p + 1)= * p; _ " - p)"为什么?以及如何使用?
_

for(int*p = &(L->elem[L->length - 1]);     for loop can be used like this ???
p >= q; --p)*(p + 1) = *p; _ "--p)" why? and How to use? _

你可能会因为在奇怪的地方划线而感到困惑。看看它是否更清晰:

You might be confusing yourself by breaking lines in odd places. See if it's clearer this way:

for(int*p = &(L->elem[L->length - 1]);
            p >= q;
            --p)
{
    *(p + 1) = *p;
}

与任何for循环一样,它由四部分组成:初始化子句,条件,advancement子句和循环体。没有什么特别不寻常的。

Like any for-loop, this consists of four parts: the initialization clause, the condition, the advancement clause, and the loop body. Nothing particularly unusual about this.


这篇关于我在for循环中有一些问题,我还没有看到像这样的code'style的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆