CSC148H1 Study Guide - Final Guide: Init, Linked List

85 views2 pages
16 Oct 2011
School
Course
Professor
katrinasavvy and 38715 others unlocked
CSC148H1 Full Course Notes
1
CSC148H1 Full Course Notes
Verified Note
1 document

Document Summary

""" linked list data structure and the node class that does into it. """ class node(object): """ stores a stingle item in the linked list chain """ def __init__(self, data, next=none): """ initialize the node with a given data value """ self. data = data self. next = next def __str__(self): """ return the string representation of this node """ return "(" + str(self. data) + " , " + str(self. next) + ")" class stack(object): """ a stack which is implemented with a linked list structure. """ def __init__(self): """ initialize this stack to be empty. """ self. front = none def push(self, item): """ add the given item to the top of the stack. For this implementation the top of the stack is the fron of the linked list. # create a node that cntains the new item new_node = node(item) # assign the next pointer of this new node to the old list new_node. next = self. front.

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers

Related Documents

Related Questions