Skip to content

Commit

Permalink
stk_size / stk_capacity
Browse files Browse the repository at this point in the history
  • Loading branch information
Chong Liu committed Jan 27, 2024
1 parent feac915 commit 2d41483
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions F01_Common_Functions/inc/common_stack.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @Author : Chong Liu
* @CreateDate : 2023-10-26 13:36:39
* @LastEditors : Chong Liu
* @LastEditTime : 2024-01-27 11:27:31
* @LastEditTime : 2024-01-27 12:03:06
* =================================================================================
* Copyright (c) 2023 by Chong Liu, All Rights Reserved.
* =================================================================================
Expand All @@ -23,8 +23,8 @@
/* Stack structure */
typedef struct {
int *stk; /* Stack array */
int stkSize; /* Stack size */
int stkCapacity; /* Stack capacity */
int stk_size; /* Stack size */
int stk_capacity; /* Stack capacity */
} Stack; /* Rename struct Stack to Stack */

/**********************************************************************************/
Expand Down
12 changes: 6 additions & 6 deletions F01_Common_Functions/src/common_stack.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
Stack *Stack_Init(int capacity) {
Stack *ret = (Stack *)malloc(sizeof(Stack)); /* NOLINT(readability/casting) */
ret->stk = (int *)malloc(sizeof(int) * capacity); /* NOLINT(readability/casting) */
ret->stkSize = 0; /* 当前栈大小为0 */
ret->stkCapacity = capacity; /* 记录栈容量 */
ret->stk_size = 0; /* 当前栈大小为0 */
ret->stk_capacity = capacity; /* 记录栈容量 */
return ret; /* 返回创建的栈结构体 */
}

Expand All @@ -45,7 +45,7 @@ Stack *Stack_Init(int capacity) {
* @return {void}
*/
void Stack_Push(Stack *obj, int x) {
obj->stk[obj->stkSize++] = x; /* 将数据存入栈结构体内数组的【栈大小】索引位置,存入后将【栈大小】+ 1 */
obj->stk[obj->stk_size++] = x; /* 将数据存入栈结构体内数组的【栈大小】索引位置,存入后将【栈大小】+ 1 */
}

/**
Expand All @@ -55,7 +55,7 @@ void Stack_Push(Stack *obj, int x) {
* @return {void}
*/
void Stack_Pop(Stack *obj) {
obj->stkSize--; /* 将【栈大小】- 1 */
obj->stk_size--; /* 将【栈大小】- 1 */
}

/**
Expand All @@ -65,7 +65,7 @@ void Stack_Pop(Stack *obj) {
* @return {int} x 栈顶元素
*/
int Stack_Top(Stack *obj) {
return obj->stk[obj->stkSize - 1]; /* 返回栈结构体内【栈大小 - 1】索引位置处的数据 */
return obj->stk[obj->stk_size - 1]; /* 返回栈结构体内【栈大小 - 1】索引位置处的数据 */
}

/**
Expand All @@ -75,7 +75,7 @@ int Stack_Top(Stack *obj) {
* @return {bool} 栈是否为空
*/
bool Stack_IsEmpty(Stack *obj) {
return obj->stkSize == 0; /* 返回确认 stkSize 栈大小是否为0 */
return obj->stk_size == 0; /* 返回确认 stk_size 栈大小是否为0 */
}

/**
Expand Down

0 comments on commit 2d41483

Please sign in to comment.