Task 5 is changed

This commit is contained in:
AZEN-SGG 2025-05-22 18:52:04 +03:00
parent e5b2c01295
commit 36497ec462
50 changed files with 1007904 additions and 144 deletions

1004879
2025.05.23/10Ex/input/big_a.txt Normal file

File diff suppressed because it is too large Load diff

View file

@ -17,6 +17,16 @@ int get_length (node * head)
return i;
}
void delete_list (node * head)
{
node *curr, *next;
for (curr = head; curr; curr = next) {
next = curr->next;
free(curr->string);
free(curr);
}
}
void delete_nodes (node *head, const int count)
{
for (int i = 0; i < count; ++i)
@ -28,19 +38,10 @@ void delete_nodes (node *head, const int count)
}
}
void delete_list (node * head)
{
node *curr, *next;
for (curr = head; curr; curr = next) {
next = curr->next;
delete_node(curr);
}
}
io_status read_list (node **list, const char *filename)
{
FILE *fp = 0;
char *string, buf[LEN_STR];
char *string, buf[LEN_STR] = {0};
node *head, *lunit, *unit;
head = lunit = unit = NULL;
@ -50,6 +51,7 @@ io_status read_list (node **list, const char *filename)
while (fgets(buf, LEN_STR, fp))
{
int len = strcspn(buf, "\n");
unit = (node *)malloc(sizeof(node));
if (!unit) {
fclose(fp);
@ -60,8 +62,8 @@ io_status read_list (node **list, const char *filename)
unit->next = NULL;
buf[strcspn(buf, "\n")] = '\0';
string = strdup(buf);
buf[len] = '\0';
string = (char *)malloc((len+1) * sizeof(char));
if (!string) {
fclose(fp);
free(unit);
@ -70,6 +72,8 @@ io_status read_list (node **list, const char *filename)
return ERR_MEM;
}
strcpy(string, buf);
unit->string = string;
if (!lunit)
head = unit;