is anyone know what is problem at lst_print_rev function? it is last function. i
ID: 3768136 • Letter: I
Question
is anyone know what is problem at lst_print_rev function? it is last function. it give 63 [Warning] passing arg 1 of `lst_print_rev' from incompatible pointer type <- im not sure also this one at 64 line which is p ->val has problem...
->structure has no member named `val'
also how to make same as this reverse function but not allocate any new memory,,,? is this same as my code? or is different? i really not understand this concept. please help me
#include
#include
#include
#include "list.h"
typedef struct node {
ElemType val;
struct node *next;
} NODE;
struct list_struct {
NODE *front;
NODE *back;
};
/*
* returns pointer to newly created empty list
*/
LIST *lst_create() {
LIST *l = malloc(sizeof(LIST));
l->front = NULL;
l->back = NULL;
return l;
}
void lst_free(LIST *l) {
NODE *p = l->front;
NODE *pnext;
while(p != NULL) {
pnext = p->next; // keeps us from de-referencing a freed ptr
free(p);
p = pnext;
}
// now free the LIST
free(l);
}
void lst_print(LIST *l) {
NODE *p = l->front;
printf("[");
while(p != NULL) {
printf(FORMAT, p->val);
p = p->next;
}
printf("] ");
}
/**
* TODO: print in reverse order
*
* Try to do without looking at notes!
* Hints: recursive helper function
*/
void lst_print_rev(LIST *l) {
NODE *p = l->back;
if (p == NULL) return;
lst_print_rev(p ->next);
printf(FORMAT, p->val);
}
Explanation / Answer
void lst_print_rev(LIST *l) {
NODE *p = l->back;
if (p == NULL) return;
printf(FORMAT, p->val);
lst_print_rev(p ->next);
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.