typedef struct stack_node {
ETYPE data;
struct stack_node *prev, *next;
}NODE;
struct seq_struct {
// "Container" struct
NODE* top, *bottom;
int size;
};
void seq_add_front(Seq seq, ETYPE val){
/* create a node to be added to the front of the sequence */
NODE* topq = malloc(sizeof(NODE));
topq->data = val;
if(seq->top==NULL){
topq->prev=NULL;
topq->next=NULL;
seq->top = topq;
seq->bottom=topq;
}
else{
topq->prev=NULL;
topq->next=NULL;
seq->top=topq;
seq->bottom=topq->next;
//seq->top=topq;
}
/* increment the size */
seq->size++;
}
私のelseステートメントの何が問題なのかを理解するためにあなたの助けが必要です. if(seq->top!=NULL) 前の値を保持する方法がわかりません。
私の最初の問題は、C構造体のシーケンスの最後に要素を追加することであり、この関数によって上書きされていました。今、私はそれを書き直し、新しい値を追加しながら seq->bottom の値を保持する方法を理解する必要があります。