Last active
August 29, 2015 14:16
-
-
Save strftime/7af39f52fdd4108efcb1 to your computer and use it in GitHub Desktop.
stack
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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