first: bottom
pointer in the seq_struct
should be initiated to NULL
second: before calling
seq->bottom->next=endq;
seq->bottom = endq;
you have to check if seq->bottom
is not NULL
. so your code should looks like this
if (seq->bottom != NULL)
seq->bottom->next=endq;
seq->bottom = endq;
You have to take in account the first element to insert in your linked list with your function seq_add_back()
.
So you have to update your seq->bottom
also if it's the first elemenent to insert in the linked list.
The seq->bottom
should be initiated to NULL.
and you have to add the following code at the end of your function seq_add_back()
:
if (seq->top == NULL)
seq->top = endq;
So as summary your function should look like this:
void seq_add_back(Seq seq, ETYPE val){
NODE* endq = malloc(sizeof(NODE));
endq->next =NULL;
endq->prev = seq->bottom;
endq->data = val;
if (seq->bottom != NULL)
seq->bottom->next=endq;
seq->bottom = endq;
if (seq->top == NULL)
seq->top = endq;
seq->size++;
return;
}