#define elem_type int

添加`#define elem_type int` 方便后期更改类型
This commit is contained in:
Jdhggg 2025-03-21 13:07:47 +08:00
parent ff8b779b7b
commit 361849b19f
10 changed files with 53 additions and 39 deletions

View File

@ -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

View File

@ -2,69 +2,73 @@
#include <stdlib.h>
#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);
}
}

View File

@ -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);

View File

@ -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;

View File

@ -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);

View File

@ -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)

View File

@ -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);