湖北建设厅官方网站,如何在腾讯云上网站建设,博客园网站开发,wordpress 空白页面一、函数实现顺序栈的其他函数实现#xff0c;请看之前的博客链接《数据结构与算法基础-学习-09-线性表之栈的理解、初始化顺序栈、判断顺序栈空、获取顺序栈长度的实现》。1、ClearSqStack#xff08;1#xff09;用途清理栈的空间。只需要栈顶指针和栈底指针相等#xff…一、函数实现顺序栈的其他函数实现请看之前的博客链接《数据结构与算法基础-学习-09-线性表之栈的理解、初始化顺序栈、判断顺序栈空、获取顺序栈长度的实现》。1、ClearSqStack1用途清理栈的空间。只需要栈顶指针和栈底指针相等就说明栈已经清空后续新入栈的数据可以直接覆盖不用实际清理数据提升了清理效率。2源码Status ClearSqStack(SqStack* S)
{JudgeAllNullPointer(S);S-TopPointer S-BasePointer;Log(Clear SqStack : OK\n,Info);return SuccessFlag;
}3参数参数名说明S需要清理的SqStack*类型顺序栈。2、DestroyStack1说明销毁栈。释放申请的资源。2源码Status DestroyStack(SqStack* S)
{JudgeAllNullPointer(S);free(S-BasePointer);S-TopPointer NULL;S-BasePointer NULL;S-SqStackMaxSize 0;Log(Destroy SqStack : OK\n,Info);return SuccessFlag;
}3参数参数名说明S需要销毁的SqStack*类型顺序栈。3、PushSqStack1说明压栈。判断栈是否已满如果已满报错反之将数据压入栈顶即可。2源码Status PushSqStack(SqStack* S, SqElemType SE)
{JudgeAllNullPointer(S);//判断是否栈满if(GetSqStackLen(S) S-SqStackMaxSize){Log(SqStack is Full, Data cannot be pushed\n,Warning);return FailFlag;}//相同结构体之间可以直接赋值。*(S-TopPointer) SE;//CopySqElemType(S-TopPointer, SE);//printf(%p, %p\n,S-TopPointer-StudentNum, (SE)-StudentNum);S-TopPointer;Log(Push SqStack : OK\n,Info);return SuccessFlag;
}3参数参数名说明S需要压栈的SqStack*类型顺序栈。SE需要压入栈的SqElemType类型数据。4、PopSqStack1说明弹栈。判断栈是否已空如果是就抛出错误。如果不是就下移栈顶指针将数据赋值给SE作为传出参数。2源码Status PopSqStack(SqStack* S, SqElemType* SE)
{JudgeAllNullPointer(S);JudgeAllNullPointer(SE);if(JudgeSqStackIsEmpty(S) SuccessFlag){Log(SqStack is Empty, Data cannot be poped\n,Warning);return FailFlag;}S-TopPointer--;*SE *(S-TopPointer);//CopySqElemType(SE,S-TopPointer);//printf(%p, %p\n,S-TopPointer-StudentNum, SE-StudentNum);Log(Pop SqStack : OK\n,Info);return SuccessFlag;
}3参数参数名说明S需要初始化的SqStack*类型顺序栈。SE需要弹出栈的SqElemType*类型数据。二、虚机测试[gbaseczg2 LinearTable_SqStack]$ make
gcc -Wall -O3 ../Log/Log.c SqStack.c main.c -o TestSqStack -I ../Log/[gbaseczg2 LinearTable_SqStack]$ ./TestSqStack
2023-2--Info--Init SqStack : OK
2023-2--Info--Push SqStack : OK
2023-2--Info--Push SqStack : OK
2023-2--Info--Push SqStack : OK
2023-2--Info--Push SqStack : OK
2023-2--Info--Push SqStack : OK
2023-2--Info--Push SqStack : OK
2023-2--Warning--SqStack is Full, Data cannot be pushed
2023-2--Warning--SqStack is Full, Data cannot be pushed
2023-2--Debug--Judge SqStack : Not Empty
2023-2--Debug--SqStack Data :
StudentNum : X666
StudentName : Sun
StudentScore : 100StudentNum : X666
StudentName : Sun
StudentScore : 101StudentNum : X666
StudentName : Sun
StudentScore : 102StudentNum : X666
StudentName : Sun
StudentScore : 103StudentNum : X666
StudentName : Sun
StudentScore : 104StudentNum : X666
StudentName : Sun
StudentScore : 105SqStackLen : 6
SqStackMaxSize : 6
2023-2--Debug--Judge SqStack : Not Empty
2023-2--Info--Pop SqStack : OK
2023-2--Debug--SqElemType Data:
StudentNum : X666
StudentName : Sun
StudentScore : 105
2023-2--Debug--Judge SqStack : Not Empty
2023-2--Info--Pop SqStack : OK
2023-2--Debug--SqElemType Data:
StudentNum : X666
StudentName : Sun
StudentScore : 104
2023-2--Debug--Judge SqStack : Not Empty
2023-2--Info--Pop SqStack : OK
2023-2--Debug--SqElemType Data:
StudentNum : X666
StudentName : Sun
StudentScore : 103
2023-2--Debug--Judge SqStack : Not Empty
2023-2--Info--Pop SqStack : OK
2023-2--Debug--SqElemType Data:
StudentNum : X666
StudentName : Sun
StudentScore : 102
2023-2--Debug--Judge SqStack : Not Empty
2023-2--Info--Pop SqStack : OK
2023-2--Debug--SqElemType Data:
StudentNum : X666
StudentName : Sun
StudentScore : 101
2023-2--Debug--Judge SqStack : Not Empty
2023-2--Info--Pop SqStack : OK
2023-2--Debug--SqElemType Data:
StudentNum : X666
StudentName : Sun
StudentScore : 100
2023-2--Debug--Judge SqStack : Empty
2023-2--Warning--SqStack is Empty, Data cannot be poped
2023-2--Debug--Judge SqStack : Empty
2023-2--Warning--SqStack is Empty, Data cannot be poped
2023-2--Debug--SqStack Data :
SqStackLen : 0
SqStackMaxSize : 6
2023-2--Info--Clear SqStack : OK
2023-2--Info--Destroy SqStack : OK