1、初始化
bool CreateLinkStack(LinkList **head)
{
*head = NULL;
return true;
}
2、压栈
bool Push(LinkList **head, ElemType e)
{
LinkList *tmp;
tmp = (LinkList *)malloc(sizeof(LinkList));
if (tmp == NULL)
{
return false;
}
tmp->data = e;
tmp->next = *head;
*head = tmp;
return true;
}
3、弹出栈顶元素
bool Pop(LinkList **head, ElemType *e)
{
LinkList *tmp;
tmp = *head;
if (tmp == NULL)
{
return false;
}
*e = tmp->data;
*head = tmp->next;
free(tmp);
return true;
}
4、删除栈
bool DelStack(LinkList **head)
{
LinkList *tmp;
while (*head)
{
tmp = (*head)->next;
free(*head);
*head = tmp;
}
return true;
}
5、获取栈顶元素
bool GetTop(LinkList *L, ElemType *e)
{
if (L == NULL)
{
return false;
}
*e = L->data;
return true;
}
阅读(683) | 评论(0) | 转发(0) |