Task 3 is done
This commit is contained in:
parent
8f1d1cccff
commit
34f67b3187
3 changed files with 18 additions and 6 deletions
|
@ -3,18 +3,30 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
int t2_solve (node *head)
|
int t3_solve (node *head)
|
||||||
{
|
{
|
||||||
char *last = head->string;
|
char *last = head->string;
|
||||||
int count = 1;
|
int count = 0, local = 1;
|
||||||
|
|
||||||
for (head = head->next; head; head = head->next)
|
for (head = head->next; head; head = head->next)
|
||||||
{
|
{
|
||||||
if (strcmp(head->string, last) > 0)
|
int cmp = strcmp(head->string, last);
|
||||||
count++;
|
if (cmp < 0) {
|
||||||
|
if (local) {
|
||||||
|
count += local;
|
||||||
|
local = 0;
|
||||||
|
}
|
||||||
|
} else if (cmp == 0) {
|
||||||
|
if (local)
|
||||||
|
local++;
|
||||||
|
} else
|
||||||
|
local = 1;
|
||||||
|
|
||||||
last = head->string;
|
last = head->string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
count += local;
|
||||||
|
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,6 @@
|
||||||
|
|
||||||
#include "node.h"
|
#include "node.h"
|
||||||
|
|
||||||
int t2_solve (node *head);
|
int t3_solve (node *head);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue