A
azrael
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
but this was not dinamicly enough for me (or my prof.) so i did the
following:
but deleting the list[1] willl automaticly make the list[2] become
list[1] and list[0] will "point" new to list[1]= 3
For my prof i should be doing something like deleting movig the
pointer from pointing to list[1] to list[2]. If I would do this in C
then the old list[1] would be lost, but not in python. If i just
redirect the "pointer" then the old value is still there.
I think that my concept is wrong by using a list to create a list. Is
it possible to manage the insertation of new object like in C by
allocating new memory space.
any sugestions how to make the implementation more like in C. I never
managed the syntax of C so I stoped when structs crossed my way.
Please help. I dont want to learn C. And especialy not in 2 days.
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
but this was not dinamicly enough for me (or my prof.) so i did the
following:
list=[]
list.append(Node(1))
list.append(Node(2))
list[0].next=list[1]
list.append(Node(3))
list[1].next=list[2]
but deleting the list[1] willl automaticly make the list[2] become
list[1] and list[0] will "point" new to list[1]= 3
For my prof i should be doing something like deleting movig the
pointer from pointing to list[1] to list[2]. If I would do this in C
then the old list[1] would be lost, but not in python. If i just
redirect the "pointer" then the old value is still there.
I think that my concept is wrong by using a list to create a list. Is
it possible to manage the insertation of new object like in C by
allocating new memory space.
any sugestions how to make the implementation more like in C. I never
managed the syntax of C so I stoped when structs crossed my way.
Please help. I dont want to learn C. And especialy not in 2 days.