Data structure and algorithms

Terry Reedy tjreedy at udel.edu
Mon Jan 29 02:24:24 EST 2007


"azrael" <jura.grozni at gmail.com> wrote in message 
news:1170024965.321036.206010 at m58g2000cwm.googlegroups.com...
| Hy, i am a student and in 2 days I am writing a test in data
| structures and algorithms. I've done my homework and understood all
| the implementations and structures. My profesor was so kind to allow
| us to use any programing language we want, and I'd like to use
| pythhon. At the first look it looked great, but we are not allowed to
| use the built in functions like append(), so i have to write my own.
| I tried it like this:
|
| class Node:
|  def __init__(self, cargo=None, next=None):
|    self.cargo = cargo
|    self.next  = next
|
|  def __str__(self):
|    return str(self.cargo)
|
|
| then
|
| >>> node1 = Node(1)
| >>> node2 = Node(2)
| >>> node3 = Node(3)
|
| >>> node1.next = node2
| >>> node2.next = node3

This is the standard idiom in Python for linked lists and other linked 
structures and perhaps what you should be doing.

|
| but this was not dinamicly enough for me (or my prof.) so

dynamic?  I have no idea what you mean by 'not dynamic enough'.

Python is not C or C++.  It does not have pointers.  Trying to program in C 
in Python does not work too well.

Terry Jan Reedy






More information about the Python-list mailing list