up linked_list
完善: 插入 获取length 获取地址
This commit is contained in:
parent
4cab56956a
commit
8db20e924d
@ -1,25 +1,2 @@
|
|||||||
array_queue.c
|
main.c
|
||||||
array_stack.c
|
|
||||||
C:\code\lencode\C_DS_Algo\array_queue.c(1,1): warning C4819: 该文件包含不能在当前代码页(936)中表示的字符。请将该文件保存为 Unicode 格式以防止数据丢失
|
|
||||||
C:\code\lencode\C_DS_Algo\array_queue.h(1,1): warning C4819: 该文件包含不能在当前代码页(936)中表示的字符。请将该文件保存为 Unicode 格式以防止数据丢失
|
|
||||||
(编译源文件“array_queue.c”)
|
|
||||||
|
|
||||||
C:\code\lencode\C_DS_Algo\array_queue.c(22,5): warning C4013: “memset”未定义;假设外部返回 int
|
|
||||||
C:\code\lencode\C_DS_Algo\array_stack.c(12,5): warning C4013: “memset”未定义;假设外部返回 int
|
|
||||||
linked_list.c
|
|
||||||
linked_list_stack.c
|
|
||||||
C:\code\lencode\C_DS_Algo\linked_list_stack.c(26,3): warning C4098: “push_stack_linked”:“void”函数返回值
|
|
||||||
main.c
|
|
||||||
C:\code\lencode\C_DS_Algo\array_queue.h(1,1): warning C4819: 该文件包含不能在当前代码页(936)中表示的字符。请将该文件保存为 Unicode 格式以防止数据丢失
|
|
||||||
(编译源文件“main.c”)
|
|
||||||
|
|
||||||
C:\code\lencode\C_DS_Algo\main.c(39,22): warning C4013: “init_array_queue”未定义;假设外部返回 int
|
|
||||||
C:\code\lencode\C_DS_Algo\main.c(39,18): warning C4047: “初始化”:“array_queue *”与“int”的间接级别不同
|
|
||||||
sq_list.c
|
|
||||||
C:\code\lencode\C_DS_Algo\sq_list.c(107,9): warning C4033: “locate_list”必须返回值
|
|
||||||
C:\code\lencode\C_DS_Algo\sq_list.c(117,9): warning C4033: “locate_list”必须返回值
|
|
||||||
C:\code\lencode\C_DS_Algo\sq_list.c(171,34): warning C4047: “函数”:“int”与“sq_list *”的间接级别不同
|
|
||||||
C:\code\lencode\C_DS_Algo\sq_list.c(171,34): warning C4024: “locate_list”: 形参和实参 2 的类型不同
|
|
||||||
正在生成代码...
|
|
||||||
C:\code\lencode\C_DS_Algo\sq_list.c(121,1): warning C4715: “locate_list”: 不是所有的控件路径都返回值
|
|
||||||
Project2.vcxproj -> C:\code\lencode\C_DS_Algo\Debug\Project2.exe
|
Project2.vcxproj -> C:\code\lencode\C_DS_Algo\Debug\Project2.exe
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Project2/Debug/linked_list.obj.enc
Normal file
BIN
Project2/Debug/linked_list.obj.enc
Normal file
Binary file not shown.
BIN
Project2/Debug/main.obj.enc
Normal file
BIN
Project2/Debug/main.obj.enc
Normal file
Binary file not shown.
@ -33,10 +33,9 @@ void replace_node(node* n, elem_type value)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 插入节点
|
// 插入节点
|
||||||
void insert_node(node* head, elem_type value)
|
void insert_node(node* head,node *new_node)
|
||||||
{
|
{
|
||||||
node* new_node = init_node(value);
|
new_node->next = head->next;
|
||||||
new_node->next = head->next->next;
|
|
||||||
head->next = new_node;
|
head->next = new_node;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,14 +53,16 @@ address_node *find_node(node* head, elem_type value)
|
|||||||
printf("内存分配失败\n");
|
printf("内存分配失败\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
n->n = 0;
|
n->n = 1;
|
||||||
n->p = head;
|
n->p = head->next;
|
||||||
while (head != NULL)
|
node *temp = head;
|
||||||
|
while (temp->next != NULL)
|
||||||
{
|
{
|
||||||
if (head->value == value)
|
if (temp->value == value)
|
||||||
return n;
|
return n;
|
||||||
n->n += 1;
|
n->n += 1;
|
||||||
head = head->next;
|
temp = temp->next;
|
||||||
|
n->p = temp;
|
||||||
}
|
}
|
||||||
printf("无法找到节点\n");
|
printf("无法找到节点\n");
|
||||||
free(n);
|
free(n);
|
||||||
@ -71,20 +72,24 @@ address_node *find_node(node* head, elem_type value)
|
|||||||
// 打印链表
|
// 打印链表
|
||||||
void print_node_list(node* head)
|
void print_node_list(node* head)
|
||||||
{
|
{
|
||||||
while (head->next != NULL)
|
node* head_1 = head;
|
||||||
|
printf("[%d ",head_1->value);
|
||||||
|
while (head_1->next != NULL)
|
||||||
{
|
{
|
||||||
head = head->next;
|
head_1 = head_1->next;
|
||||||
printf("%d ", head->value);
|
printf("%d ", head_1->value);
|
||||||
}
|
}
|
||||||
|
printf("]\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获得链表长度
|
// 获得链表长度
|
||||||
int get_node_list(node* head)
|
int get_node_list(node* head)
|
||||||
{
|
{
|
||||||
int i = 0;
|
node *head_1 = head;
|
||||||
while (head->next != NULL)
|
int i = 1;
|
||||||
|
while (head_1->next != NULL)
|
||||||
{
|
{
|
||||||
head = head->next;
|
head_1 = head_1->next;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
printf("链表长度为%d\n", i);
|
printf("链表长度为%d\n", i);
|
||||||
@ -93,13 +98,16 @@ int get_node_list(node* head)
|
|||||||
|
|
||||||
|
|
||||||
// 获得元素
|
// 获得元素
|
||||||
elem_type get_node_value(node* head,int pos,elem_type value)
|
elem_type get_node_value(node* head,int pos)
|
||||||
{
|
{
|
||||||
|
node* head_1 = head;
|
||||||
int i = 1;
|
int i = 1;
|
||||||
while (i <= pos)
|
while (i < pos && head_1)
|
||||||
{
|
{
|
||||||
head = head->next;
|
head_1 = head_1->next;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
return head->value;
|
if (head_1 == NULL || i != pos)
|
||||||
|
return;
|
||||||
|
return head_1->value;
|
||||||
}
|
}
|
@ -11,7 +11,7 @@ typedef struct node
|
|||||||
typedef struct address_node
|
typedef struct address_node
|
||||||
{
|
{
|
||||||
int n;
|
int n;
|
||||||
node* p;
|
elem_type * p;
|
||||||
}address_node;
|
}address_node;
|
||||||
|
|
||||||
|
|
||||||
@ -25,7 +25,7 @@ void delete_node(node* n);
|
|||||||
void replace_node (node* n, elem_type value);
|
void replace_node (node* n, elem_type value);
|
||||||
|
|
||||||
// 插入节点
|
// 插入节点
|
||||||
void insert_node(node* head, elem_type value);
|
void insert_node(node* head,node *new_node);
|
||||||
|
|
||||||
//访问节点
|
//访问节点
|
||||||
int get_node(node* n);
|
int get_node(node* n);
|
||||||
@ -40,7 +40,7 @@ void print_node_list(node* head);
|
|||||||
int get_node_list(node* head);
|
int get_node_list(node* head);
|
||||||
|
|
||||||
// 获的
|
// 获的
|
||||||
elem_type get_node_value(node* head,int pos,elem_type value);
|
elem_type get_node_value(node* head,int pos);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
24
main.c
24
main.c
@ -1,9 +1,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "array_stack.h"
|
#include "linked_list.h"
|
||||||
#include "sq_list.h"
|
|
||||||
#include "array_queue.h"
|
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
@ -36,7 +34,7 @@ int main(void)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
array_queue *q = init_array_queue();
|
/* array_queue *q = init_array_queue();
|
||||||
push_array_queue(q,0);
|
push_array_queue(q,0);
|
||||||
push_array_queue(q,1);
|
push_array_queue(q,1);
|
||||||
push_array_queue(q,2);
|
push_array_queue(q,2);
|
||||||
@ -46,7 +44,23 @@ int main(void)
|
|||||||
print_array_queue(q);
|
print_array_queue(q);
|
||||||
printf("----------\n");
|
printf("----------\n");
|
||||||
push_array_queue(q, 666);
|
push_array_queue(q, 666);
|
||||||
print_array_queue(q);
|
print_array_queue(q);*/
|
||||||
|
|
||||||
|
node* q1 = init_node(1);
|
||||||
|
node* q2 = init_node(2);
|
||||||
|
node* q3 = init_node(3);
|
||||||
|
node* q4 = init_node(4);
|
||||||
|
q1->next = q2;
|
||||||
|
q2->next = q3;
|
||||||
|
q3->next = q4;
|
||||||
|
//address_node *n = find_node(q1, 3);
|
||||||
|
// printf("%d\n %p\n", n->n,n->p
|
||||||
|
//int e = get_node_list(q1);
|
||||||
|
node* q2_3 = init_node(0);
|
||||||
|
insert_node(q2, q2_3);
|
||||||
|
print_node_list(q1);
|
||||||
|
delete_node(q2);
|
||||||
|
print_node_list(q1);
|
||||||
printf("Hello World!\n");
|
printf("Hello World!\n");
|
||||||
system("pause");
|
system("pause");
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user