千家信息网

【C语言数据结构】顺序栈

发表于:2025-01-22 作者:千家信息网编辑
千家信息网最后更新 2025年01月22日,SeqStack.h#ifndef SEQSTACK_H#define SEQSTACK_Htypedef void SeqStack;SeqStack* SeqStack_Create(int ca
千家信息网最后更新 2025年01月22日【C语言数据结构】顺序栈

SeqStack.h

#ifndef SEQSTACK_H#define SEQSTACK_Htypedef void SeqStack;SeqStack* SeqStack_Create(int capacity);void SeqStack_Destroy(SeqStack* stack);void SeqStack_Clear(SeqStack* stack);int SeqStack_Push(SeqStack* stack, void* item);void* SeqStack_Pop(SeqStack* stack);void* SeqStack_Top(SeqStack* stack);int SeqStack_Size(SeqStack* stack);int SeqStack_Capacity(SeqStack* stack);#endif // SEQSTACK_H

SeqStack.c

#include "SeqStack.h"#include "SeqList.h"SeqStack* SeqStack_Create(int capacity){    return SeqList_Create(capacity);}void SeqStack_Destroy(SeqStack* stack){    SeqList_Destroy(stack);}void SeqStack_Clear(SeqStack* stack){    SeqList_Clear(stack);}int SeqStack_Push(SeqStack* stack, void* item){    return SeqList_Insert(stack,item,SeqList_Length(stack));}void* SeqStack_Pop(SeqStack* stack){    return SeqList_Remove(stack,SeqList_Length(stack) - 1);}void* SeqStack_Top(SeqStack* stack){    return SeqList_Get(stack,SeqList_Length(stack) - 1);}int SeqStack_Size(SeqStack* stack){    return SeqList_Length(stack);}int SeqStack_Capacity(SeqStack* stack){    return SeqList_Capacity(stack);}


0