65 lines
1.2 KiB
C
65 lines
1.2 KiB
C
/*
|
|
*
|
|
* stack.c
|
|
*
|
|
* ADD ALL YOUR CODE HERE AND SUBMIT ONLY stack.c
|
|
*
|
|
* Be sure to test functionality with all input files
|
|
*
|
|
* and eliminate all memory leaks
|
|
*
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <stdint.h>
|
|
#include <string.h>
|
|
|
|
#include "stack.h"
|
|
|
|
|
|
|
|
/* Push(...) : adds a new node containing value to the top of the stack assuming stack is not full */
|
|
void Push(struct Node** headPtr, int value)
|
|
{
|
|
struct Node * ptr = (struct Node*) malloc(sizeof(struct Node));
|
|
ptr->data = value;
|
|
ptr->nextPtr = *headPtr;
|
|
*headPtr=ptr;
|
|
}
|
|
|
|
/* Pop(...) : removes and frees node from top of stack, returning the data from the removed node,
|
|
* assuming the stack is not empty
|
|
*/
|
|
int Pop(struct Node** headPtr)
|
|
{
|
|
struct Node * ptr = *headPtr;
|
|
int data = ptr->data;
|
|
ptr->nextPtr = *headPtr;
|
|
|
|
ptr->nextPtr=NULL;
|
|
|
|
|
|
return data;
|
|
}
|
|
|
|
/* Clear(...) : removes and frees all nodes from stack */
|
|
void Clear(struct Node** headPtr)
|
|
{
|
|
|
|
}
|
|
|
|
/* Size(...) : returns the number of nodes currently stored in the stack */
|
|
uint32_t Size(struct Node* headPtr)
|
|
{
|
|
struct Node * ptr = (struct Node*) malloc(sizeof(struct Node));
|
|
|
|
|
|
return 0; /* Replace this statement with correct code */
|
|
}
|
|
|
|
|
|
|
|
|
|
|