首页 > 其他 > 详细

数据结构笔记2链栈

时间:2015-12-02 18:08:02      阅读:335      评论:0      收藏:0      [点我收藏+]

#include<stdio.h>
#include<conio.h>
#include<malloc.h>
#define MAX 100
struct node{
 int data;
 struct *next;
}s;
//初始化 
int InitStack(&s){
 s=(node *)malloc(sizeof(node));
 if(NULL==s)
  return -1;
 s->next=NULL;
}
//判空
int StackEmpty(&s){
 if(NULL==s->next)
  return 1;
 return 0;

//求长度
int StackLength(&s){
 int count=0;
 node *p=s;
 while(NULL!=p->next){
  p=p->next;
  count++;
 }
 return count;

//访问栈顶 
int GetTop(&s,int *e){
 if(StackEmpty(*s))
  return -1;
 *e=s->next->data;
 return 0;
}
//入栈
int Push(&s,int e){
 node *p;
 p=(node *)malloc(sizeof(node));
 if(p==NULL)
  return -1;
 p->data=e;
 p->next=s->next;
 s->next=p;
 return 0;

//出栈 
int Pop(&s,int *e){
 node *p=NULL;
 if(StackEmpty(*s))
  return -1;
 p=s->next;
 *e=p->data;
 s->next=p->next;
 free(p);
 return 0;
}
//主函数
int main(){
 
}

数据结构笔记2链栈

原文:http://www.cnblogs.com/100114jerro/p/4998735.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!