第八周

---恢复内容开始---

下周就是其中考了,感觉没底气,因为没有复习完。如果说慌张是因为没有准备好,那么我希望从现在开始慢慢赶上。这周最让我印象深刻的就是数据结构中的出栈进栈。打了代码,发现数据结构虽然也挺有趣的。

例:

#define MaxStackSize 100//栈中最多容纳个数
typedef int ElemType;//设栈中元素为int型
typedef struct {
   ElemType *stack;//动态数组
    int top; 
} Stack;
void InitStack ( Stack *S)
{  
 
S->stack=(ElemType *)malloc
                            (MaxStackSize*sizeof(ElemType));
S->top = -1;
}
 
void Push (Stack *S,  ElemType e)
{
    if (S->top == MaxStackSize-1)
{ printf(“栈满了。 ”);
return;
}
S->top++;
    S->elem[S->top] = e;  //加入新元素
}
void Pop(Stack *S, ElemType *e)
{
 
    if( S->top ==-1)
{ printf(“栈为空。 ”);
return ;
}
 
*e= S->stack[S->top];
         S->top--;
}
 

---恢复内容结束---

原文地址:https://www.cnblogs.com/lsx1989/p/5426082.html