Compare commits

..

No commits in common. "fc334bbfca2234f8d62225c43bb5b005ef3a2923" and "cf39e5499fd0d9c499fe575b43fd5e6ad037949d" have entirely different histories.

11 changed files with 92 additions and 391 deletions

8
.gitignore vendored
View File

@ -57,11 +57,3 @@ dkms.conf
*.recipe
*.tlog
*.log
*.vcxproj
*.filters
Project2.vcxproj.filters
*.filters
*.vcxproj
Project2.vcxproj
Project2.vcxproj.filters
main.c

View File

@ -1,51 +0,0 @@
# 定义编译器
CC = gcc
# 定义源文件目录
SRC_DIR = .
# 定义头文件目录
INC_DIR = .
# 定义目标文件目录
OBJ_DIR = obj
# 定义可执行文件名称
TARGET = main
# 定义源文件后缀
SRC_EXT = .c
# 定义目标文件后缀
OBJ_EXT = .o
# 定义源文件列表
SRC_FILES = \
array_queue.c \
array_stack.c \
linked_list_stack.c \
linked_list.c \
sq_list.c \
main.c
# 使用正则表达式替换源文件后缀为.o生成目标文件列表
OBJ_FILES = $(patsubst $(SRC_DIR)/%$(SRC_EXT), $(OBJ_DIR)/%$(OBJ_EXT), $(SRC_FILES))
# 定义编译选项
CFLAGS = -I$(INC_DIR) -Wall -Wextra -pedantic
# 默认目标,调用链接规则
all: $(TARGET)
# 链接规则,将所有目标文件链接成可执行文件
$(TARGET): $(OBJ_FILES)
$(CC) $(CFLAGS) $^ -o $@
# 编译规则,将源文件编译成目标文件
$(OBJ_DIR)/%$(OBJ_EXT): $(SRC_DIR)/%$(SRC_EXT)
@mkdir -p $(OBJ_DIR)
$(CC) $(CFLAGS) -c $< -o $@
# 清理目标文件和可执行文件
clean:
rm -rf $(OBJ_DIR) $(TARGET)

View File

@ -21,20 +21,16 @@
<ItemGroup>
<ClCompile Include="array_queue.c" />
<ClCompile Include="array_stack.c" />
<ClCompile Include="binary_tree.c" />
<ClCompile Include="linked_list.c" />
<ClCompile Include="linked_list_stack.c" />
<ClCompile Include="linked_queue.c" />
<ClCompile Include="main.c" />
<ClCompile Include="sq_list.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="array_queue.h" />
<ClInclude Include="array_stack.h" />
<ClInclude Include="binary_tree.h" />
<ClInclude Include="linked_list.h" />
<ClInclude Include="linked_list_stack.h" />
<ClInclude Include="linked_queue.h" />
<ClInclude Include="sq_list.h" />
</ItemGroup>
<PropertyGroup Label="Globals">

View File

@ -33,12 +33,6 @@
<ClCompile Include="sq_list.c">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="linked_queue.c">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="binary_tree.c">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="sq_list.h">
@ -56,11 +50,5 @@
<ClInclude Include="array_queue.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="linked_queue.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="binary_tree.h">
<Filter>头文件</Filter>
</ClInclude>
</ItemGroup>
</Project>

View File

@ -1,61 +0,0 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "binary_tree.h"
tree_node *init_binary_tree(elem_type value)
{
tree_node *node = (tree_node *)malloc(sizeof(tree_node));
if (node == NULL)
{
printf("error: malloc failed from:init_binary_tree\n");
}
node->value = value;
node->left = NULL;
node->right = NULL;
return node;
}
// 插入节点
void insert_tree_node(tree_node *node,tree_node *node_new)
{
if (node == NULL)
{
node ->left = node_new;
return;
}
tree_node *temp = node;
node ->left = node_new;
}
// 删除节点
// 遍历树节点 bfs
void traverse_tree(tree_node *roots)
{
tree_node *queue[3] = {NULL,NULL,NULL};
int front = 0;
int rear = 0;
if (roots == NULL)
{
printf("error: roots is NULL\n");
return;
}
printf("%d\n", roots->value);
while(roots ->left != NULL && roots -> right != NULL)
{
tree_node *temp[2] = {roots->left,roots->right};
for (int i = 0;i<2;i++)
{
if (temp[i] != NULL)
{
queue[rear] = temp[i];
rear = (rear + 1) % 3;
printf("%d ",temp[i]->value);
}
}
printf("\n");
roots = queue[front];
front = (front+1) % 3;
}
}

View File

@ -1,18 +0,0 @@
#ifndef BINARY_TREE
#define BINARY_TREE
#define elem_type int
typedef struct tree_node
{
elem_type value;
struct tree_node *left;
struct tree_node *right;
}tree_node;
// 初始化树节点
tree_node *init_binary_tree(elem_type value);
// 插入节点
void insert_tree_node(tree_node *node,tree_node *node_new);
// 删除节点
void delete_node(tree_node *node);
// 遍历树节点
void traverse_tree(tree_node *roots);
#endif // DEBUG

View File

@ -73,14 +73,11 @@ address_node *find_node(node* head, elem_type value)
void print_node_list(node* head)
{
node* head_1 = head;
//printf("[%d ",head_1->value);
printf("[");
while (1)
printf("[%d ",head_1->value);
while (head_1->next != NULL)
{
printf("%d ", head_1->value);
head_1 = head_1->next;
if (head_1 == NULL)
break;
printf("%d ", head_1->value);
}
printf("]\n");
}

View File

@ -2,13 +2,13 @@
#include <stdlib.h>
#include "linked_list_stack.h"
// <EFBFBD><EFBFBD>ʼջ
// 初始栈
stack_linked* init_stack_linked(void)
{
stack_linked* s = (stack_linked*)malloc(sizeof(stack_linked));
if (s == NULL)
{
printf("<EFBFBD>ڴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>\n");
printf("内存分配失败!\n");
return NULL;
}
s->top = NULL;
@ -16,13 +16,13 @@ stack_linked* init_stack_linked(void)
return s;
}
// <EFBFBD><EFBFBD>ջ
// 入栈
void push_stack_linked(stack_linked* s, elem_type value)
{
stack_node* node = (stack_node*)malloc(sizeof(stack_node));
if (node == NULL)
{
printf("<EFBFBD>ڴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>\n");
printf("内存分配失败!\n");
return NULL;
}
node->value = value;
@ -31,7 +31,7 @@ void push_stack_linked(stack_linked* s, elem_type value)
s->size++;
}
// <EFBFBD><EFBFBD>ջ
// 出栈
int pop_stack_linked(stack_linked* s)
{
int flog = 0;

View File

@ -1,91 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include "linked_queue.h"
link_queue* init_link_queue()
{
link_queue* q = (link_queue*)malloc(sizeof(link_queue));
if (q == NULL)
{
printf("error: malloc from init_link_queue failed\n");
return;
}
q->front = NULL;
q->rear = NULL;
q->size = 0;
return q;
}
// Èë¶Ó
void push_link_queue(link_queue* q, elem_type value)
{
node* new_node = (node*)malloc(sizeof(node));
if (new_node == NULL)
{
printf("error: malloc from push_link_queue failed\n");
return;
}
new_node->value = value;
new_node->next = NULL;
if (q->front == NULL)
{
q->front = new_node;
q->rear = new_node;
}
else
{
q->rear->next = new_node;
q->rear = new_node;
}
q->size++;
}
// ³ö¶Ó
elem_type pop_link_queue(link_queue* q)
{
if (empty_link_queue(q))
{
printf("error: pop from empty link_queue\n");
return;
}
link_queue* tmp = q->front;
elem_type a = q->front->value;
q->front = q->front->next;
q->size--;
return a;
}
// ÅпÕ
int empty_link_queue(link_queue* q)
{
if (q->size == 0)
{
return 1;
}
else
{
return 0;
}
}
// ´òÓ¡
int print_link_queue(link_queue* q)
{
if (empty_link_queue(q))
{
printf("error: queue empty form: print_link_queue\n");
return;
}
node* head = q->front;
printf("[");
while (1)
{
printf(" %d ", head->value);
head = head->next;
if (head == NULL)
break;
}
printf("]\n");
}

View File

@ -1,34 +0,0 @@
#ifndef LINKED_QUEUE_H
#define LINKED_QUEUE_H
#define elem_type int
typedef struct node
{
elem_type value;
struct node* next;
} node;
typedef struct linked_queue
{
struct node* front;
struct node* rear;
int size;
}link_queue;
// 初始化
link_queue* init_link_queue();
// 入队
void push_link_queue(link_queue* q, elem_type value);
// 出队
elem_type pop_link_queue(link_queue* q);
// 判空
int empty_link_queue(link_queue* q);
// 打印
int print_link_queue(link_queue* q);
#endif

41
main.c
View File

@ -1,8 +1,9 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "binary_tree.h"
int main(void) {
int main(void)
{
//sq_list* L = init_sq_list();
//sq_list* N = init_sq_list();
@ -39,11 +40,14 @@ int main(void) {
print_sq_list(L);
printf("L->length:[%d]\n", L->length);*/
/* array_stack* stack = init_array_stack();
push_array_stack(stack, 1);
push_array_stack(stack, 2);
push_array_stack(stack, 3);*/
/* array_queue *q = init_array_queue();
push_array_queue(q,0);
push_array_queue(q,1);
@ -72,16 +76,18 @@ int main(void) {
// delete_node(q2);
// print_node_list(q1);
/* stack_linked* head = init_stack_linked();
/*
stack_linked* head = init_stack_linked();
push_stack_linked(head, 1);
push_stack_linked(head, 2);
push_stack_linked(head, 3);
print_linked(head);
pop_stack_linked(head);
print_linked(head);*/
print_linked(head);
*/
// queue_test();
/*array_queue *q = init_array_queue();
array_queue *q = init_array_queue();
push_array_queue(q, 1);
push_array_queue(q, 2);
push_array_queue(q, 3);
@ -91,30 +97,7 @@ int main(void) {
print_array_queue(q);
printf("----------\n");
push_array_queue(q, 666);
print_array_queue(q);*/
/* link_queue* q = init_link_queue();
push_link_queue(q, 1);
push_link_queue(q, 2);
push_link_queue(q, 3);
print_link_queue(q);
printf("____________________\n");
pop_link_queue(q);
print_link_queue(q);*/
tree_node *root = init_binary_tree(1);
tree_node *node1 = init_binary_tree(2);
tree_node *node2 = init_binary_tree(3);
tree_node *node3 = init_binary_tree(4);
tree_node *node4 = init_binary_tree(5);
tree_node *node5 = init_binary_tree(6);
tree_node *node6 = init_binary_tree(7);
root->left = node1;
root->right = node2;
node1->left = node3;
node1->right = node4;
node2->left = node5;
node2->right = node6;
traverse_tree(root);
print_array_queue(q);
printf("Hello World!\n");
system("pause");
return 0;