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

📄 stack2.h

📁 自己做的数据结构实验题(合并链表
💻 H
字号:
#include<stdio.h>
#include<malloc.h>

typedef char ElemType;

typedef struct Node{
	ElemType data;
	Node *next;
}Node;
typedef Node *Stack,*Position;


//Create a stack
Stack CreateStack()
{
	Node *S;
	S=(Stack)malloc(sizeof(Node));
	S->next=NULL;
	return S;
}

//Push element into stack
void Push(Stack S,ElemType e){
	Node *TempCell;
	TempCell=(Node*)malloc(sizeof(Node));
	TempCell->data=e;
	TempCell->next=S->next;
	S->next=TempCell;
}


//put the top element of stack out
void Pop(Stack S,ElemType &e){
	if(S->next!=NULL)
		e=S->next->data;
	Position a=S->next;
	S->next=S->next->next;
	free(a);
}

void ClearStack(Stack S){
	Position p,q;
	q=p=S->next;
	while(p){
		p=p->next;
		free(q);
		q=p;
	}
	S->next=NULL;	
}

int IsEmptyStack(Stack S){
	return(S->next==NULL);
}

ElemType Top(Stack S){
return S->next->data;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -