Skip to content

Commit

Permalink
cm
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaojiedi committed Apr 16, 2022
1 parent 5fd7223 commit 13bd542
Show file tree
Hide file tree
Showing 18 changed files with 241 additions and 46 deletions.
Empty file added Expired
Empty file.
2 changes: 1 addition & 1 deletion source/code/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ project(code C)
set(CMAKE_C_STANDARD 99)

#add_executable(code list_base.c)
add_executable(code link_base.c)
add_executable(code stack_link_base.c)
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#IncludeRegexTransform:

/Users/bytedance/github/zhaojiedi1992/My_Study_DataStruct/source/code/link_base.c
/Users/bytedance/github/zhaojiedi1992/My_Study_DataStruct/source/code/stack_link_base.c
stdio.h
-
stdlib.h
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set(CMAKE_DEPENDS_LANGUAGES
)
# The set of files for implicit dependencies of each language:
set(CMAKE_DEPENDS_CHECK_C
"/Users/bytedance/github/zhaojiedi1992/My_Study_DataStruct/source/code/link_base.c" "/Users/bytedance/github/zhaojiedi1992/My_Study_DataStruct/source/code/cmake-build-debug/CMakeFiles/code.dir/link_base.c.o"
"/Users/bytedance/github/zhaojiedi1992/My_Study_DataStruct/source/code/stack_link_base.c" "/Users/bytedance/github/zhaojiedi1992/My_Study_DataStruct/source/code/cmake-build-debug/CMakeFiles/code.dir/stack_link_base.c.o"
)
set(CMAKE_C_COMPILER_ID "AppleClang")

Expand Down
24 changes: 12 additions & 12 deletions source/code/cmake-build-debug/CMakeFiles/code.dir/build.make
Original file line number Diff line number Diff line change
Expand Up @@ -57,27 +57,27 @@ include CMakeFiles/code.dir/progress.make
# Include the compile flags for this target's objects.
include CMakeFiles/code.dir/flags.make

CMakeFiles/code.dir/link_base.c.o: CMakeFiles/code.dir/flags.make
CMakeFiles/code.dir/link_base.c.o: ../link_base.c
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green --progress-dir=/Users/bytedance/github/zhaojiedi1992/My_Study_DataStruct/source/code/cmake-build-debug/CMakeFiles --progress-num=$(CMAKE_PROGRESS_1) "Building C object CMakeFiles/code.dir/link_base.c.o"
/Library/Developer/CommandLineTools/usr/bin/cc $(C_DEFINES) $(C_INCLUDES) $(C_FLAGS) -o CMakeFiles/code.dir/link_base.c.o -c /Users/bytedance/github/zhaojiedi1992/My_Study_DataStruct/source/code/link_base.c
CMakeFiles/code.dir/stack_link_base.c.o: CMakeFiles/code.dir/flags.make
CMakeFiles/code.dir/stack_link_base.c.o: ../stack_link_base.c
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green --progress-dir=/Users/bytedance/github/zhaojiedi1992/My_Study_DataStruct/source/code/cmake-build-debug/CMakeFiles --progress-num=$(CMAKE_PROGRESS_1) "Building C object CMakeFiles/code.dir/stack_link_base.c.o"
/Library/Developer/CommandLineTools/usr/bin/cc $(C_DEFINES) $(C_INCLUDES) $(C_FLAGS) -o CMakeFiles/code.dir/stack_link_base.c.o -c /Users/bytedance/github/zhaojiedi1992/My_Study_DataStruct/source/code/stack_link_base.c

CMakeFiles/code.dir/link_base.c.i: cmake_force
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green "Preprocessing C source to CMakeFiles/code.dir/link_base.c.i"
/Library/Developer/CommandLineTools/usr/bin/cc $(C_DEFINES) $(C_INCLUDES) $(C_FLAGS) -E /Users/bytedance/github/zhaojiedi1992/My_Study_DataStruct/source/code/link_base.c > CMakeFiles/code.dir/link_base.c.i
CMakeFiles/code.dir/stack_link_base.c.i: cmake_force
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green "Preprocessing C source to CMakeFiles/code.dir/stack_link_base.c.i"
/Library/Developer/CommandLineTools/usr/bin/cc $(C_DEFINES) $(C_INCLUDES) $(C_FLAGS) -E /Users/bytedance/github/zhaojiedi1992/My_Study_DataStruct/source/code/stack_link_base.c > CMakeFiles/code.dir/stack_link_base.c.i

CMakeFiles/code.dir/link_base.c.s: cmake_force
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green "Compiling C source to assembly CMakeFiles/code.dir/link_base.c.s"
/Library/Developer/CommandLineTools/usr/bin/cc $(C_DEFINES) $(C_INCLUDES) $(C_FLAGS) -S /Users/bytedance/github/zhaojiedi1992/My_Study_DataStruct/source/code/link_base.c -o CMakeFiles/code.dir/link_base.c.s
CMakeFiles/code.dir/stack_link_base.c.s: cmake_force
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green "Compiling C source to assembly CMakeFiles/code.dir/stack_link_base.c.s"
/Library/Developer/CommandLineTools/usr/bin/cc $(C_DEFINES) $(C_INCLUDES) $(C_FLAGS) -S /Users/bytedance/github/zhaojiedi1992/My_Study_DataStruct/source/code/stack_link_base.c -o CMakeFiles/code.dir/stack_link_base.c.s

# Object files for target code
code_OBJECTS = \
"CMakeFiles/code.dir/link_base.c.o"
"CMakeFiles/code.dir/stack_link_base.c.o"

# External object files for target code
code_EXTERNAL_OBJECTS =

code: CMakeFiles/code.dir/link_base.c.o
code: CMakeFiles/code.dir/stack_link_base.c.o
code: CMakeFiles/code.dir/build.make
code: CMakeFiles/code.dir/link.txt
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green --bold --progress-dir=/Users/bytedance/github/zhaojiedi1992/My_Study_DataStruct/source/code/cmake-build-debug/CMakeFiles --progress-num=$(CMAKE_PROGRESS_2) "Linking C executable code"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
file(REMOVE_RECURSE
"CMakeFiles/code.dir/link_base.c.o"
"CMakeFiles/code.dir/stack_link_base.c.o"
"code"
"code.pdb"
)
Expand Down
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
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

2 changes: 1 addition & 1 deletion source/code/cmake-build-debug/CMakeFiles/code.dir/link.txt
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 not shown.
36 changes: 18 additions & 18 deletions source/code/cmake-build-debug/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -123,32 +123,32 @@ code/fast:
$(MAKE) -f CMakeFiles/code.dir/build.make CMakeFiles/code.dir/build
.PHONY : code/fast

link_base.o: link_base.c.o
stack_link_base.o: stack_link_base.c.o

.PHONY : link_base.o
.PHONY : stack_link_base.o

# target to build an object file
link_base.c.o:
$(MAKE) -f CMakeFiles/code.dir/build.make CMakeFiles/code.dir/link_base.c.o
.PHONY : link_base.c.o
stack_link_base.c.o:
$(MAKE) -f CMakeFiles/code.dir/build.make CMakeFiles/code.dir/stack_link_base.c.o
.PHONY : stack_link_base.c.o

link_base.i: link_base.c.i
stack_link_base.i: stack_link_base.c.i

.PHONY : link_base.i
.PHONY : stack_link_base.i

# target to preprocess a source file
link_base.c.i:
$(MAKE) -f CMakeFiles/code.dir/build.make CMakeFiles/code.dir/link_base.c.i
.PHONY : link_base.c.i
stack_link_base.c.i:
$(MAKE) -f CMakeFiles/code.dir/build.make CMakeFiles/code.dir/stack_link_base.c.i
.PHONY : stack_link_base.c.i

link_base.s: link_base.c.s
stack_link_base.s: stack_link_base.c.s

.PHONY : link_base.s
.PHONY : stack_link_base.s

# target to generate assembly for a file
link_base.c.s:
$(MAKE) -f CMakeFiles/code.dir/build.make CMakeFiles/code.dir/link_base.c.s
.PHONY : link_base.c.s
stack_link_base.c.s:
$(MAKE) -f CMakeFiles/code.dir/build.make CMakeFiles/code.dir/stack_link_base.c.s
.PHONY : stack_link_base.c.s

# Help Target
help:
Expand All @@ -159,9 +159,9 @@ help:
@echo "... rebuild_cache"
@echo "... edit_cache"
@echo "... code"
@echo "... link_base.o"
@echo "... link_base.i"
@echo "... link_base.s"
@echo "... stack_link_base.o"
@echo "... stack_link_base.i"
@echo "... stack_link_base.s"
.PHONY : help


Expand Down
Binary file modified source/code/cmake-build-debug/code
Binary file not shown.
2 changes: 1 addition & 1 deletion source/code/cmake-build-debug/code.cbp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
</MakeCommands>
</Target>
</Build>
<Unit filename="/Users/bytedance/github/zhaojiedi1992/My_Study_DataStruct/source/code/link_base.c">
<Unit filename="/Users/bytedance/github/zhaojiedi1992/My_Study_DataStruct/source/code/stack_link_base.c">
<Option target="code"/>
</Unit>
<Unit filename="/Users/bytedance/github/zhaojiedi1992/My_Study_DataStruct/source/code/CMakeLists.txt">
Expand Down
71 changes: 71 additions & 0 deletions source/code/stack_link_base.c
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;
/*
*/
}
99 changes: 99 additions & 0 deletions source/code/stack_list_base.c
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
*/
}

32 changes: 32 additions & 0 deletions source/基本数据结构/02-堆栈.rst
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:
7 changes: 0 additions & 7 deletions source/基本数据结构/03-堆栈.rst

This file was deleted.

File renamed without changes.

0 comments on commit 13bd542

Please sign in to comment.