A stack is actually reasonably simple to implement as a singly linked list, due to its restricted push and pop operations. It's actually a lot easier if you insert pushed elements at the head of the list. Since it's homework, I'll provide pseudo-code.
To initialise a stack, it's simply creating:
top -> null
with this code:
def init (stk):
stk->top = null # just initialise to empty.
Pushing an item is actually inserting it at the start of the list. So, when you push 3, 4 and 5, you get:
+---+
top -> | 3 | -> null
+---+
+---+ +---+
top -> | 4 | -> | 3 | -> null
+---+ +---+
+---+ +---+ +---+
top -> | 5 | -> | 4 | -> | 3 | -> null
+---+ +---+ +---+
with the following code:
def push (stk, val):
item = new node # Create the node.
item->value = val # Insert value.
item->next = stk->top # Point it at current top.
stk->top = item # Change top pointer to point to it.
And popping is then just removing that first node.
def pop (stk):
if stk->top == null: # Catch stack empty error.
abort with "stack empty"
first = stk->top # Save it for freeing.
val = first->value # Get the value from the top.
stk->top = first->next # Set top to the top's next.
free first # Release the memory.
return val # Return the value.