当前位置: 代码迷 >> 综合 >> 链栈
  详细解决方案

链栈

热度:44   发布时间:2024-02-13 19:58:42.0

一 LinKStack 

节点类型
struct node 
{
DATATYPE data;
struct node *next;
};

栈头的类型
typedef struct
{
//记录栈顶的位置
struct node *top;
//记录栈中元素的个数
int n;
}LinKStack;

A.创建空栈 
LinKStack *create_empty_stack()
{
LinKStack *s;

    s = (LinKStack *)malloc(sizeof(LinKStack));
s->top = NULL;
s->n  = 0;

    return s;
}

B.入栈 
int push_stack(LinKStack *s,DATATYPE data)
{

}

C.空栈
int is_empty_stack(LinKStack *s);

D.出栈
DATATYPE pop_stack(LinKStack *s);

F.获得栈顶元素
DATATYPE get_top_stack(LinKStack *s);

Code:

#include <stdio.h>
#include <stdlib.h>typedef int DATATYPE;//节点的类型
struct node 
{DATATYPE data;struct node *next;
};//栈头的类型
typedef struct 
{//栈顶元素的位置struct node *top;//栈中元素
  相关解决方案