2025-03-17 14:00:57 +08:00
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include "sq_list.h"
|
|
|
|
|
|
2025-03-17 14:24:44 +08:00
|
|
|
|
sq_list* init_sq_list(sq_list *name)
|
2025-03-17 14:00:57 +08:00
|
|
|
|
{
|
|
|
|
|
name = (sq_list*)malloc(sizeof(sq_list));
|
|
|
|
|
memset(name, 0, sizeof(sq_list));
|
|
|
|
|
}
|
2025-03-17 14:24:44 +08:00
|
|
|
|
|
|
|
|
|
// ɾ<><C9BE>
|
|
|
|
|
void delete_sq_list(sq_list* list,int pos)
|
|
|
|
|
{
|
|
|
|
|
if (pos < 0 || pos > list->length || list->length == MAX)
|
|
|
|
|
{
|
|
|
|
|
printf("λ<EFBFBD>ô<EFBFBD><EFBFBD><EFBFBD>\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (pos == list->length - 1)
|
|
|
|
|
list->data[pos] = 0;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
for (int i = pos; i < list->length - 1; i++)
|
|
|
|
|
list->data[i] = list->data[i + 1];
|
|
|
|
|
list->data[list->length - 1] = 0;
|
|
|
|
|
}
|
|
|
|
|
list->length--;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// <20>滻
|
|
|
|
|
void replace_sq_list(sq_list* list, int pos, int value)
|
|
|
|
|
{
|
|
|
|
|
if (pos < 0 || pos > list->length || list->length >= MAX)
|
|
|
|
|
{
|
|
|
|
|
printf("λ<EFBFBD>ô<EFBFBD><EFBFBD><EFBFBD>\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (pos > list->length && pos <= MAX)
|
|
|
|
|
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ˴<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
list->data[pos] = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>
|
|
|
|
|
void insert_sq_list(sq_list* list, int pos, int value)
|
|
|
|
|
{
|
|
|
|
|
if (pos < 0 || pos > list->length || list->length >= MAX)
|
|
|
|
|
{
|
|
|
|
|
printf("λ<EFBFBD>ô<EFBFBD><EFBFBD><EFBFBD>\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (pos == MAX)
|
|
|
|
|
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
|
2025-03-17 14:33:15 +08:00
|
|
|
|
if (pos > list->length && pos <= MAX)
|
2025-03-17 14:24:44 +08:00
|
|
|
|
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ˴<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
int i = list->length;
|
|
|
|
|
int flog = i;
|
|
|
|
|
for (i; i > pos; i--)
|
|
|
|
|
{
|
|
|
|
|
list->data[i + 1] = list->data[i];
|
|
|
|
|
}
|
2025-03-17 16:27:15 +08:00
|
|
|
|
list->data[pos] = value;
|
2025-03-17 14:24:44 +08:00
|
|
|
|
if (flog + 1 > list->length)
|
|
|
|
|
list->length++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// <20><>ӡ
|
|
|
|
|
void print_sq_list(sq_list* list)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < list->length; i++)
|
|
|
|
|
printf("%d ", list->data[i]);
|
|
|
|
|
printf("\n");
|
|
|
|
|
}
|