star

搜索

RSS

RSS Link

计数器

140160
数据结构头文件Ver2.0
队列的头文件

栈的头文件

Star posted @ 2010年10月05日 04:00 in C语言 with tags 数据结构 链式栈 , 3877 阅读
/* 数据结构 栈的实现 Stack.h
 * author : star
 */
 
//防止重复定义
#ifndef STACK_H
#define STACK_H

#include "defs.h"

//初始化大小为n的栈 
int InitSqstack(SQSTACK *S, int n)
{
	S->data = (ElemType *)malloc(n * sizeof(ElemType));
	if(S->data == NULL)
		return 0;
	S->size = n;
	S->top  = -1;
	return 1;
}

//销毁栈
void DestroySqstack(SQSTACK *S)
{
	free(S->data);
	S->data = NULL;
	S->top  = -1;
	S->size = 0;
}

//判断栈空、栈满
int IsSqstackEmpty(SQSTACK S)
{
	return S.top == -1;
}

int IsSqstackFull(SQSTACK S)
{
	return S.top == S.size-1;
}

//入栈
int PushS(SQSTACK *S, ElemType e)
{
	if(IsSqstackFull(*S))
		return 0;
	++S->top;
	S->data[S->top] = e;
	return 1;
}

//出栈
int PopS(SQSTACK *S, ElemType *e)
{
	if(IsSqstackEmpty(*S))
		return 0;
	*e = S->data[S->top];
	--S->top;
	return 1;
}

//初始化链式栈
int InitLinkstack(LINKSTACK *S)
{
	*S = (LINKSTACK)malloc(sizeof(LSNODE));
	if(*S == NULL)
		return 0;
	(*S)->next = NULL;
	return 1;
}

//销毁链式栈
int DestroyLinkstack(LINKSTACK *S)
{
	LSNODEPTR q, p;
	p = *S;
	while(p)
	{
		q = p;
		p = p->next;
		free(q);
	}
	*S = NULL;
}

//判断链栈空、满
IsLinkstackEmpty(LINKSTACK S)
{
	return S->next == NULL;
}

IsLinkstackFull(LINKSTACK S)
{
	return S->next != NULL;
}

//入链栈 
int PushL(LINKSTACK S, ElemType e)
{
	LSNODEPTR p;
	p = (LSNODEPTR)malloc(sizeof(LSNODE));
	if(p == NULL)
		return 0;
	p->data = e;
	p->next = S->next;
	S->next = p;
	return 1;
}

//出链栈
int PopL(LINKSTACK S, ElemType *e)
{
	LSNODEPTR p;
	p = S->next;
	if(p == NULL)
		return 0;
	S->next = p->next;
	*e = p->data;
	free(p);
	return 1;
}

#endif
TN Board 9th Model P 说:
2022年8月25日 16:23

Tamil Nadu Board Class 9th English Paper 2, Tamil Nadu Board Class 9th First Term Question Paper 2023, Tamil Nadu Board Class 9th Social Question Paper 2023, Tamil Nadu Board Class 9th English Paper 2, Tamil Nadu TN Board 9th Model Paper 2023 Board Class 9th Model Paper 2023, SA, FA Exam, Tamil Nadu Board Class 9th Model Paper 2023, Term 1 & 2, Tamil Nadu Board Class 9th Question Paper 2023, Tamil Nadu Board Class 9th Question Paper 2023, and Tamil Nadu Board Class

Grade 8 Result rajsh 说:
2022年8月30日 21:21

Bangladesh Education Board DPE has conducted the class 8th grade of Junior School Certificate Exam and Junior Dakhil Certificate Exam on 1st to 15th November 2022 at all centers in division wise under Ministry of Primary and Mass Education (MOPME), and the class 8th grade terminal examination tests are successfully conducted for all eligible JSC/JDC students for the academic year of 2022. Grade 8 Result rajshahi The Bangladesh government Minister of Secondary Education is going to announce the JSC Result 2022 in student wise for division students in education board wise, and the result documents will be submitted to the Prime Minister of the country after then the result with mark sheet will be announced to public to check the individual result.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter