Skip to content

Instantly share code, notes, and snippets.

@strftime
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save strftime/7af39f52fdd4108efcb1 to your computer and use it in GitHub Desktop.
Save strftime/7af39f52fdd4108efcb1 to your computer and use it in GitHub Desktop.
stack
#include <stdio.h>
#include <stdlib.h>
typedef struct{
int num;
}DataType;
typedef struct LSstk{
DataType data;
struct node *next;
}LSstk;
//初始化
int InitLSstk(LSstk *LS){
LS = (LSstk *)malloc(sizeof(LSstk));
LS->next = NULL;
return 1;
}
//判断栈是否为空
int EmptyLSstk(LSstk *LS){
if(LS->next == NULL){
return 1;
}else{
return 0;
}
}
int Push(LSstk *LS,DataType data){
LSstk *temp;
temp = (LSstk *)malloc(sizeof(LSstk));
temp->data = data;
temp->next = LS->next;
LS->next = temp;
return 1;
}
int Pop(LSstk *LS){
if(!EmptyLSstk(LS)){
LSstk *temp;
temp = LS->next;
LS->next = temp->next;
free(temp);
return 1;
}
}
DataType GetTop(LSstk *LS){
if(EmptyLSstk(LS)){
exit(0);
}else{
return LS->next->data; //报错
//error: dereferencing pointer to incomplete type
}
}
void main(){
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment