⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stack.c

📁 本次实验
💻 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 + -