?? stack.c
字號:
#include <stdio.h>
#include<malloc.h>
#include "stack.h"
int IsEmpty(Stack S)
{
return S->Next==NULL;
}
void Pop(Stack S)
{
PtrToNode FirstCell;
if(IsEmpty(S))
printf("Empty stack");
else
{
FirstCell=S->Next;
S->Next=S->Next->Next;
free(FirstCell);
}
}
Stack CreateStack(void)
{
Stack S;
S=(PtrToNode)malloc(sizeof(struct Node));
if(S==NULL)
printf("Out of space!!!");
MakeEmpty(S);
return S;
}
ElmentType Top(Stack S)
{
if(!IsEmpty(S))
return S->Next->Elment;
printf("Empty stack");
return 0;
}
void Push(ElmentType X,Stack S)
{
PtrToNode TmpCell;
TmpCell=(PtrToNode)malloc(sizeof(struct Node));
if(TmpCell==NULL)
printf("Out of space!!!");
else
{
TmpCell->Elment=X;
TmpCell->Next=S->Next;
S->Next=TmpCell;
}
}
void MakeEmpty(Stack S)
{
if(S==NULL)
printf("Must use CreateStack first");
else
S->Next=NULL;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -