Ejemplo n.º 1
0
PtrT StackPushNew(StackT *self) {
  if (self->top < (int)TableSize(self->data)) {
    self->top++;
    return StackGet(self, 0);
  }
  return NULL;
}
Ejemplo n.º 2
0
int main()
{
    SqStack S;
    printf("(1)��ʼ��ջ��\n");
    InitStack (S);
    printf("(2)�ж�ջs�Ƿ�ǿգ�");
    if(StackEmpty(S))
        printf("�ǿ�\n");
    else printf("��\n");
    printf("(3)���ν�ջԪ��a,b,c,d,e:\n");
    push(S,'a');
    push(S,'b');
    push(S,'c');
    push(S,'d');
    push(S,'e');
    printf("(4)�ж�ջs�Ƿ�ǿգ�");
    if(StackEmpty(S))
        printf("�ǿ�\n");
    else printf("��\n");

    printf("(5)ջ�ij����ǣ�%d\n",StackLength(S));
    printf("(6)�����ջ����ջ��Ԫ��:");
    StackTraverse(S);
    printf("\n(7)�����ջ����:");
    StackGet(S);

    printf("\n(8)�ж�ջs�Ƿ�ǿգ�");
    if(StackEmpty(S))
        printf("�ǿ�\n");
    else printf("��\n");

    printf("(9)�ͷ�ջ");
    DestroyStack(S);

}
Ejemplo n.º 3
0
PtrT StackPeek(StackT *self, size_t index) {
  return (self->top >= index) ? StackGet(self, index) : NULL;
}