链表完毕
This commit is contained in:
parent
2d99fe1c7e
commit
7cace1073e
@ -1,3 +1,4 @@
|
||||
sq_list.c
|
||||
C:\code\lencode\Project2\sq_list.c(10,1): warning C4716: “init_sq_list”: 必须返回一个值
|
||||
linked_list.c
|
||||
C:\code\lencode\Project2\linked_list.c(31,24): warning C4028: 形参 1 与声明不同
|
||||
C:\code\lencode\Project2\linked_list.c(59,2): warning C4047: “return”:“address_node *”与“int”的间接级别不同
|
||||
Project2.vcxproj -> C:\code\lencode\Project2\Debug\Project2.exe
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -24,5 +24,47 @@ void delete_node(node* n)
|
||||
// 替换节点值
|
||||
void replace_node(node* n, int val)
|
||||
{
|
||||
|
||||
n->value = val;
|
||||
}
|
||||
|
||||
// 插入节点
|
||||
void insert_node(node* head, int val)
|
||||
{
|
||||
node* new_node = init_node(val);
|
||||
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* n = (address_node*)malloc(sizeof(address_node));
|
||||
n->n = 0;
|
||||
n->p = head;
|
||||
while(1)
|
||||
{
|
||||
if (head->value == val)
|
||||
return n;
|
||||
n->n += 1;
|
||||
head = head->next;
|
||||
}
|
||||
printf("无法找到节点\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// 打印链表
|
||||
void print_node_list(node* head)
|
||||
{
|
||||
while (head->next != NULL)
|
||||
{
|
||||
head = head->next;
|
||||
printf("%d ", head->value);
|
||||
}
|
||||
}
|
@ -7,6 +7,13 @@ typedef struct node
|
||||
struct node* next;
|
||||
} node;
|
||||
|
||||
typedef struct address_node
|
||||
{
|
||||
int n;
|
||||
node* p;
|
||||
}address_node;
|
||||
|
||||
|
||||
// 初始化节点
|
||||
node* init_node(int val);
|
||||
|
||||
@ -23,9 +30,10 @@ void insert_node(node** head, int val);
|
||||
int get_node(node* n);
|
||||
|
||||
// 查找
|
||||
int find_node(node* head, int val);
|
||||
|
||||
address_node *find_node(node* head, int val);
|
||||
|
||||
// ´òÓ¡Á´±í
|
||||
void print_node_list(node* head);
|
||||
|
||||
#endif
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user