Task 10 is done
This commit is contained in:
parent
50e9bb6d59
commit
80daf08c78
13 changed files with 349 additions and 0 deletions
56
2025.05.23/10Ex/solve.c
Normal file
56
2025.05.23/10Ex/solve.c
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
#include "solve.h"
|
||||
#include "node.h"
|
||||
#include "io_node.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
node * t10_solve (node *head)
|
||||
{
|
||||
int down = 0;
|
||||
node *last, *curr, *next,
|
||||
*start;
|
||||
last=next=start=NULL;
|
||||
curr = head;
|
||||
|
||||
for (next=curr->next; next; next=curr->next)
|
||||
{
|
||||
if (strcmp(next->string, curr->string) <= 0) {
|
||||
if (!down)
|
||||
start = last;
|
||||
down++;
|
||||
} else {
|
||||
if (down) {
|
||||
if (start) {
|
||||
delete_nodes(start->next, down+1);
|
||||
start->next = next;
|
||||
last = start;
|
||||
} else {
|
||||
delete_nodes(head, down+1);
|
||||
head = next;
|
||||
last = NULL;
|
||||
}
|
||||
curr = NULL;
|
||||
}
|
||||
down = 0;
|
||||
}
|
||||
|
||||
last = curr;
|
||||
curr = next;
|
||||
}
|
||||
|
||||
if (down) {
|
||||
if (start) {
|
||||
delete_nodes(start->next, down+1);
|
||||
start->next = NULL;
|
||||
} else {
|
||||
delete_nodes(head, down+1);
|
||||
head = NULL;
|
||||
}
|
||||
curr = NULL;
|
||||
last = NULL;
|
||||
}
|
||||
|
||||
return head;
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue