MCPcopy Create free account
hub / github.com/142vip/408CSFamily / linkStackPushNode

Function linkStackPushNode

code/ds/LinkStack.cpp:24–43  ·  view source on GitHub ↗

基于单链表链栈的进栈操作

Source from the content-addressed store, hash-verified

22
23// 基于单链表链栈的进栈操作
24bool linkStackPushNode(LinkStack* linkStack,int e){
25
26 // 判断链栈是否存在
27 if (!linkStack){
28 //链栈不存在,无法进栈操作,返回false
29 return false;
30 }
31 // 开辟栈结点元素内存控件
32 StackNode* node = (StackNode*)malloc(sizeof(StackNode));
33 // 新结点指针域指向链表,即栈顶指针位置,元素加入链表
34 node->next = linkStack->top;
35 // 新结点数据域赋值
36 node->data = e;
37 // 元素进栈,移动栈顶指针,指向新入栈的元素
38 linkStack->top = node;
39 // 链栈元素总数+1
40 linkStack->count++;
41 //链栈入栈成功,返回true
42 return true;
43}
44
45
46/*

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected