diff --git a/Project2/Debug/Project2.log b/Project2/Debug/Project2.log index 259d036..f7f75f8 100644 --- a/Project2/Debug/Project2.log +++ b/Project2/Debug/Project2.log @@ -1,2 +1,9 @@ - main.c + linked_list_stack.c + sq_list.c +C:\code\lencode\Project2\sq_list.c(102,9): warning C4033: “locate_list”必须返回值 +C:\code\lencode\Project2\sq_list.c(112,9): warning C4033: “locate_list”必须返回值 +C:\code\lencode\Project2\sq_list.c(166,34): warning C4047: “函数”:“int”与“sq_list *”的间接级别不同 +C:\code\lencode\Project2\sq_list.c(166,34): warning C4024: “locate_list”: 形参和实参 2 的类型不同 + 正在生成代码... +C:\code\lencode\Project2\sq_list.c(116,1): warning C4715: “locate_list”: 不是所有的控件路径都返回值 Project2.vcxproj -> C:\code\lencode\Project2\Debug\Project2.exe diff --git a/Project2/Debug/Project2.tlog/CL.command.1.tlog b/Project2/Debug/Project2.tlog/CL.command.1.tlog index 5c9a976..d6b583e 100644 Binary files a/Project2/Debug/Project2.tlog/CL.command.1.tlog and b/Project2/Debug/Project2.tlog/CL.command.1.tlog differ diff --git a/Project2/Debug/Project2.tlog/CL.read.1.tlog b/Project2/Debug/Project2.tlog/CL.read.1.tlog index a8ecbf7..a48189b 100644 Binary files a/Project2/Debug/Project2.tlog/CL.read.1.tlog and b/Project2/Debug/Project2.tlog/CL.read.1.tlog differ diff --git a/Project2/Debug/Project2.tlog/CL.write.1.tlog b/Project2/Debug/Project2.tlog/CL.write.1.tlog index 6fe6733..6dfaeb0 100644 Binary files a/Project2/Debug/Project2.tlog/CL.write.1.tlog and b/Project2/Debug/Project2.tlog/CL.write.1.tlog differ diff --git a/linked_list.c b/linked_list.c index d2774ea..2a1b631 100644 --- a/linked_list.c +++ b/linked_list.c @@ -2,69 +2,73 @@ #include #include "linked_list.h" - - // ʼֵ -node* init_node(int val) +node* init_node(elem_type value) { node* new_node = (node*)malloc(sizeof(node)); - new_node->value = val; + new_node->value = value; new_node->next = NULL; return new_node; } - // ɾһڵ void delete_node(node* n) { - n->next = n->next->next; - free(n->next); + if (n->next != NULL) { + node* temp = n->next; + n->next = n->next->next; + free(temp); + } } // 滻ڵֵ -void replace_node(node* n, int val) +void replace_node(node* n, elem_type value) { - n->value = val; + n->value = value; } // ڵ -void insert_node(node* head, int val) +void insert_node(node* head, elem_type value) { - node* new_node = init_node(val); + node* new_node = init_node(value); new_node->next = head->next->next; head->next = new_node; } // ʽڵ - int get_node(node* n) { return n->value; } // -address_node *find_node(node* head, int val) +address_node *find_node(node* head, elem_type value) { address_node* n = (address_node*)malloc(sizeof(address_node)); + if (n == NULL) { + printf("ڴʧ\n"); + return NULL; + } n->n = 0; n->p = head; - while(1) + while (head != NULL) { - if (head->value == val) + if (head->value == value) return n; n->n += 1; head = head->next; } printf("޷ҵڵ\n"); - return -1; + free(n); + return NULL; } // ӡ void print_node_list(node* head) { while (head->next != NULL) - { - head = head->next; - printf("%d ", head->value); - } + { + head = head->next; + printf("%d ", head->value); + } } \ No newline at end of file diff --git a/linked_list.h b/linked_list.h index 984b3c7..d095e8a 100644 --- a/linked_list.h +++ b/linked_list.h @@ -1,9 +1,10 @@ #ifndef LINKED_LIST_H #define LINKED_LIST_H +#define elem_type int typedef struct node { - int value; + elem_type value; struct node* next; } node; @@ -15,22 +16,22 @@ typedef struct address_node // ʼڵ -node* init_node(int val); +node* init_node(elem_type value); // ɾһڵ void delete_node(node* n); // 滻ڵ -void replace_node (node* n, int val); +void replace_node (node* n, elem_type value); // ڵ -void insert_node(node** head, int val); +void insert_node(node* head, elem_type value); //ʽڵ int get_node(node* n); // -address_node *find_node(node* head, int val); +address_node *find_node(node* head, elem_type value); // ӡ void print_node_list(node* head); diff --git a/linked_list_stack.c b/linked_list_stack.c index a4161ed..d1e8e90 100644 --- a/linked_list_stack.c +++ b/linked_list_stack.c @@ -12,7 +12,7 @@ stack_linked* init_stack_linked(void) } // ջ -void push_stack_linked(stack_linked* s, int value) +void push_stack_linked(stack_linked* s, elem_type value) { stack_node* node = (stack_node*)malloc(sizeof(stack_node)); node->value = value; diff --git a/linked_list_stack.h b/linked_list_stack.h index dc7bea1..46f4765 100644 --- a/linked_list_stack.h +++ b/linked_list_stack.h @@ -1,9 +1,10 @@ #ifndef LINKED_LIST_STACK_H #define LINKED_LIST_STACK_H +#define elem_type int typedef struct stack_node { - int value; + elem_type value; struct stack_node *next; }stack_node; @@ -18,7 +19,7 @@ typedef struct stack_linked stack_linked* init_stack_linked(void); // ջ -void push_stack_linked(stack_linked* s, int value); +void push_stack_linked(stack_linked* s, elem_type value); // ջ int pop_stack_linked(stack_linked* s); diff --git a/sq_list.c b/sq_list.c index 92cb36d..f698f29 100644 --- a/sq_list.c +++ b/sq_list.c @@ -31,7 +31,7 @@ void delete_sq_list(sq_list* list,int pos) } // 滻 -void replace_sq_list(sq_list* list, int pos, int value) +void replace_sq_list(sq_list* list, int pos, elem_type value) { if (pos < 0 || pos > list->length || list->length >= MAX) { @@ -45,7 +45,7 @@ void replace_sq_list(sq_list* list, int pos, int value) // -void insert_sq_list(sq_list* list, int pos, int value) +void insert_sq_list(sq_list* list, int pos, elem_type value) { if (pos < 0 || pos > list->length || list->length >= MAX) { @@ -81,7 +81,7 @@ void print_sq_list(sq_list* list) } //Ԫ -void get_sq_list(sq_list* list1, int pos, int*e) +void get_sq_list(sq_list* list1, int pos, elem_type*e) { if (list1->length == 0 || pos<0 || pos>list1->length) { @@ -93,7 +93,7 @@ void get_sq_list(sq_list* list1, int pos, int*e) } // -int locate_list(sq_list* list, int *e) +int locate_list(sq_list* list, elem_type e) { int i = 0; if (list->length == 0) @@ -122,7 +122,7 @@ void merge_sq_list(sq_list* list_1, sq_list* list_2) { if (list_1->length == 0 || list_2->length == 0) { - printf("һձ\n"); + printf("һձ\n"); return; } if ((list_1->length + list_2->length) > MAX) diff --git a/sq_list.h b/sq_list.h index 7dd531a..4a600b1 100644 --- a/sq_list.h +++ b/sq_list.h @@ -1,11 +1,12 @@ #ifndef SQ_LIST_H #define SQ_LIST_H #define MAX 100 +#define elem_type int typedef struct sq_list { - int data[MAX]; + elem_type data[MAX]; int length; } sq_list; @@ -16,19 +17,19 @@ sq_list *init_sq_list(void); void delete_sq_list(sq_list* list, int pos); // 滻 -void replace_sq_list(sq_list* list, int pos, int value); +void replace_sq_list(sq_list* list, int pos, elem_type value); // -void insert_sq_list(sq_list* list, int pos, int value); +void insert_sq_list(sq_list* list, int pos, elem_type value); // ӡ void print_sq_list(sq_list* list); //Ԫ -void get_sq_list(sq_list* list1,int pos, int *e); +void get_sq_list(sq_list* list1,int pos, elem_type *e); // -int locate_list(sq_list* list, int e); +int locate_list(sq_list* list, elem_type e); // ϲ˳1.0 void merge_sq_list(sq_list* list_1, sq_list* list_2);