45 lines
675 B
C
45 lines
675 B
C
#include <stdlib.h>
|
|
|
|
typedef struct node
|
|
{
|
|
float Value;
|
|
struct node *Next;
|
|
}node;
|
|
|
|
typedef struct
|
|
{
|
|
node *Top;
|
|
}stack;
|
|
|
|
node *alloc_node(float Value, node *Next)
|
|
{
|
|
node *NewNode = malloc(sizeof(node));
|
|
NewNode->Value = Value;
|
|
NewNode->Next = Next;
|
|
|
|
return NewNode;
|
|
}
|
|
|
|
void push(stack *Stack, float Value)
|
|
{
|
|
// TODO: implement this
|
|
node *NewNode = alloc_node(Value, Stack->Top);
|
|
Stack->Top = NewNode;
|
|
}
|
|
|
|
float pop(stack *Stack)
|
|
{
|
|
// TODO: implement this
|
|
float Result = Stack->Top->Value;
|
|
node *Top = Stack->Top->Next;
|
|
free(Stack->Top);
|
|
Stack->Top = Top;
|
|
return Result;
|
|
}
|
|
|
|
node *peak(stack *Stack)
|
|
{
|
|
// TODO: implement this
|
|
return Stack->Top;
|
|
}
|