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

📄 linstack.h

📁 编写程序
💻 H
字号:
typedef struct snode
{	
	SDataType data;
	struct snode *next;
} LSNode;

//初始化
void StackInitiate(LSNode **head)
{		
	if((*head=(LSNode*)malloc(sizeof(LSNode)))==NULL)
		exit(1);
	(*head)->next=NULL;
}

//非空否
int StackNotEmpty(LSNode *head)
{	
	if(head->next==NULL)
		return 0;
	else return 1;
}

//入栈
int StackPush(LSNode *head,SDataType x)
{	
	LSNode *p;
	if((p=(LSNode*)malloc(sizeof(LSNode)))==NULL)
	{	
		printf("内存空间不足无法插入!");
		return 0;
	}
	p->data=x;
	p->next=head->next;
	head->next=p;
	return 1;
}

//出栈
int StackPop(LSNode *head,SDataType *d)
{	
	LSNode *p=head->next;
	if(p==NULL)
	{	
		printf("堆栈已空出错!\n");
		return 0;
	}
	head->next=p->next;	
	*d=p->data;
	free(p);
	return 1;
}

//取栈顶数据元素
int StackTop(LSNode *head,SDataType *d)
{	
	if(head->next==NULL)
	{	
		printf("堆栈已空出错!\n");
		return 0;
	}
	*d=head->next->data;
	return 1;
}

//撤销动态申请空间
void StackDestroy(LSNode **head)
{	
	LSNode *p,*q;
	p=*head;
	if(p!=NULL)
	{	
		q=p;
		p=p->next;
		free(q);
	}
	*head=NULL;
}

⌨️ 快捷键说明

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