-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
zhaojiedi
committed
Apr 16, 2022
1 parent
5fd7223
commit 13bd542
Showing
18 changed files
with
241 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
source/code/cmake-build-debug/CMakeFiles/code.dir/cmake_clean.cmake
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
source/code/cmake-build-debug/CMakeFiles/code.dir/depend.internal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# CMAKE generated file: DO NOT EDIT! | ||
# Generated by "Unix Makefiles" Generator, CMake Version 3.15 | ||
|
||
CMakeFiles/code.dir/link_base.c.o | ||
/Users/bytedance/github/zhaojiedi1992/My_Study_DataStruct/source/code/link_base.c | ||
CMakeFiles/code.dir/stack_link_base.c.o | ||
/Users/bytedance/github/zhaojiedi1992/My_Study_DataStruct/source/code/stack_link_base.c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# CMAKE generated file: DO NOT EDIT! | ||
# Generated by "Unix Makefiles" Generator, CMake Version 3.15 | ||
|
||
CMakeFiles/code.dir/link_base.c.o: ../link_base.c | ||
CMakeFiles/code.dir/stack_link_base.c.o: ../stack_link_base.c | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
/Library/Developer/CommandLineTools/usr/bin/cc -g -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/code.dir/link_base.c.o -o code | ||
/Library/Developer/CommandLineTools/usr/bin/cc -g -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/code.dir/stack_link_base.c.o -o code |
Binary file added
BIN
+4.38 KB
source/code/cmake-build-debug/CMakeFiles/code.dir/stack_link_base.c.o
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
#define ElementType int | ||
#define ERROR -9999 | ||
typedef struct SNode *Stack ; | ||
struct SNode { | ||
ElementType Data; | ||
struct SNode *Next ; | ||
}; | ||
|
||
Stack CreateStack() { | ||
Stack s = (Stack)malloc(sizeof(struct SNode)) ; | ||
s->Next = NULL; | ||
return s ; | ||
} | ||
|
||
void Push(Stack s, ElementType item) { | ||
struct SNode *tmpNode; | ||
tmpNode = (struct SNode *)malloc(sizeof(struct SNode)) ; | ||
tmpNode->Data = item ; | ||
tmpNode->Next = s->Next ; | ||
s->Next = tmpNode; | ||
} | ||
int IsEmpty(Stack s){ | ||
if (s->Next == NULL){ | ||
return 1 ; | ||
} | ||
return 0 ; | ||
} | ||
|
||
ElementType Pop(Stack s) { | ||
if (IsEmpty(s)==1){ | ||
printf("null \n") ; | ||
return ERROR; | ||
} | ||
struct SNode *firstNode; | ||
ElementType itemValue ; | ||
firstNode = s->Next ; | ||
s->Next = firstNode->Next; | ||
itemValue = firstNode->Data; | ||
free(firstNode) ; | ||
return itemValue; | ||
} | ||
|
||
int main() { | ||
Stack s = CreateStack(); | ||
ElementType item ; | ||
printf("is empty ? %d\n",IsEmpty(s)); | ||
Push(s,1); | ||
Push(s,2); | ||
Push(s,3); | ||
Push(s,4); | ||
|
||
item = Pop(s) ; | ||
printf("%d\n",item ); | ||
item = Pop(s) ; | ||
printf("%d\n",item ); | ||
item = Pop(s) ; | ||
printf("%d\n",item ); | ||
item = Pop(s) ; | ||
printf("%d\n",item ); | ||
item = Pop(s) ; | ||
printf("%d\n",item ); | ||
|
||
return 0; | ||
/* | ||
*/ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
#define MAXSIZE 5 | ||
#define ElementType int | ||
#define ERROR -9999 | ||
|
||
typedef struct SNode *Stack; | ||
struct SNode { | ||
ElementType Data[MAXSIZE]; | ||
int Top; // 顶部元素的下标。 | ||
}; | ||
|
||
|
||
Stack CreateStack() { | ||
Stack s = (Stack) malloc(sizeof(struct SNode)) ; | ||
s->Top =-1; | ||
return s ; | ||
} | ||
|
||
int IsFull(Stack s) { | ||
if (s->Top == MAXSIZE - 1) { | ||
return 1; | ||
} | ||
return 0; | ||
} | ||
|
||
void Push(Stack s, ElementType item) { | ||
if (IsFull(s) == 1) { | ||
printf("is full\n"); | ||
return; | ||
} | ||
(s->Top)++; | ||
s->Data[s->Top] = item; | ||
} | ||
|
||
|
||
int IsEmpty(Stack s) { | ||
if (s->Top == -1) { | ||
return 1; | ||
} | ||
return 0; | ||
} | ||
|
||
ElementType Pop(Stack s) { | ||
if (IsEmpty(s) == 1) { | ||
printf("is null\n"); | ||
return ERROR; | ||
} | ||
|
||
ElementType item = s->Data[s->Top]; | ||
(s->Top)--; | ||
return item; | ||
} | ||
|
||
|
||
int main() { | ||
Stack s = CreateStack(); | ||
ElementType item ; | ||
printf("%d\n",IsEmpty(s)); | ||
Push(s,1); | ||
printf("%d\n",IsFull(s)); | ||
Push(s,2); | ||
Push(s,3); | ||
Push(s,4); | ||
Push(s,5); | ||
printf("%d\n",IsFull(s)); | ||
Push(s,6); | ||
printf("%d\n",IsFull(s)); | ||
item = Pop(s) ; | ||
printf("%d\n",item ); | ||
item = Pop(s) ; | ||
printf("%d\n",item ); | ||
item = Pop(s) ; | ||
printf("%d\n",item ); | ||
item = Pop(s) ; | ||
printf("%d\n",item ); | ||
item = Pop(s) ; | ||
printf("%d\n",item ); | ||
item = Pop(s) ; | ||
printf("%d\n",item ); | ||
return 0; | ||
/* | ||
1 | ||
0 | ||
1 | ||
is full | ||
1 | ||
5 | ||
4 | ||
3 | ||
2 | ||
1 | ||
is null | ||
-9999 | ||
*/ | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
========================================== | ||
栈 | ||
========================================== | ||
|
||
具有一定操作约束的线性表。 只在一端做插入和删除操作。 这一端被称为栈顶,插入称为入栈, | ||
删除称为出栈。 | ||
|
||
抽象数据结构描述 | ||
|
||
.. code-block:: text | ||
Stack CreateStack (int MaxSize): 生成空堆栈,最大长度maxsize . | ||
int IsFull (Stack s , int maxsize) : 判断是否已经满了。 | ||
void Push(Stack s,ElementType item): 插入元素。 | ||
void IsEmpty(Stack s): 判断是否为空栈,也就是一个元素没有。 | ||
ElementType Pop(Stack s): 从栈里面删除最顶部元素,并返回该元素。 | ||
栈的顺序存储具体实现 | ||
========================================== | ||
|
||
.. literalinclude:: ../code/stack_list_base.c | ||
:encoding: utf-8 | ||
:language: c | ||
:linenos: | ||
|
||
栈的链式存储具体实现 | ||
========================================== | ||
|
||
.. literalinclude:: ../code/stack_link_base.c | ||
:encoding: utf-8 | ||
:language: c | ||
:linenos: |
This file was deleted.
Oops, something went wrong.
File renamed without changes.