This commit is contained in:
@@ -1,11 +1,47 @@
|
|||||||
#include "practice.h"
|
#include "practice.h"
|
||||||
|
#include "../../utils/lists.h"
|
||||||
|
#include "../basics/basics.h"
|
||||||
|
|
||||||
int is_palindrome(struct dlist *l)
|
int is_palindrome(struct dlist *l)
|
||||||
{
|
{
|
||||||
//FIXME
|
if (!l || l->next != NULL) return 1;
|
||||||
|
|
||||||
|
struct dlist *tmp = l;
|
||||||
|
int indexb = 0;
|
||||||
|
|
||||||
|
while (tmp->next != NULL) {
|
||||||
|
|
||||||
|
indexb ++;
|
||||||
|
tmp = tmp->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
struct dlist *back = tmp;
|
||||||
|
tmp = l;
|
||||||
|
int indexp = 0;
|
||||||
|
|
||||||
|
while (indexp < indexb){
|
||||||
|
|
||||||
|
if (tmp->data != back->data) return 0;
|
||||||
|
|
||||||
|
indexp ++;
|
||||||
|
indexb --;
|
||||||
|
|
||||||
|
tmp = tmp->next;
|
||||||
|
back = back->prev;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct list *reverse(struct list *l)
|
struct list *reverse(struct list *l)
|
||||||
{
|
{
|
||||||
//FIXME
|
struct list *tmp =l;
|
||||||
|
struct list *rslt = NULL;
|
||||||
|
while(l != NULL){
|
||||||
|
rslt = list_append(rslt, l->data);
|
||||||
|
l = l->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rslt;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user