#include <stdio.h>
#include <stdlib.h>

typedef struct node
{
	char Character;
	struct node *Next;
}node;

typedef struct
{
	node *Top;
}stack;

node *alloc_node(char c, node *Next)
{
  	node *NewNode = malloc(sizeof(node));
  	NewNode->Character = c;
  	NewNode->Next = Next;
      
	return NewNode;
}

void push(stack *Stack,char c)
{
	// TODO: implement this
	node *NewNode = alloc_node(c, Stack->Top);
	Stack->Top = NewNode;
}

char pop(stack *Stack)
{
	// TODO: implement this
	char Result = Stack->Top->Character;
	node *Top = Stack->Top->Next;
	free(Stack->Top);
	Stack->Top = Top;
	return Result;
}

node *peak(stack *Stack)
{
	// TODO: implement this	
	return Stack->Top;
}

int main(int argc, char **argv)
{
	stack Stack = {};
	char *String = "!dlroW olleH";

	// When everything works, the program should print Hello World!.
	while(*String)
	{
		push(&Stack, *String++);
	}
	while(peak(&Stack))
	{
		printf("%c", pop(&Stack));
	}
	
}
