Linked Lists 161
• gettop, returns a copy of the data block at the top of the stack without
removing the node from the stack.
• pop, removes the node from the top of the s tack.
• push, inserts a new node to the top of the s tack.
• getsize, re turns the number of nodes currently in the stack.
The most dire ct way to implement a stack is with a single-list linked list
in which insertions and deletions are p erformed at the fr ont of the linked list.
The two-ended linked list class TeLinkedList is used to implement class Stack,
which is stored in files stack.py. Listing 10.2 shows the Python source code
of class Stack.
Listing 10.2: Python implementation of class Stack .
1 # A simple class for a stack using two-ended Linked List
2 from telinklistc impor ...