izthrower's Profile User Rating: -----

Reputation: 13 Tradesman
Group:
Active Members
Active Posts:
233 (0.15 per day)
Joined:
11-February 09
Profile Views:
5,671
Last Active:
User is offline Oct 15 2012 09:43 AM
Currently:
Offline

Previous Fields

Country:
US
OS Preference:
Windows
Favorite Browser:
Chrome
Favorite Processor:
Intel
Favorite Gaming Platform:
Playstation
Your Car:
Nissan
Dream Kudos:
0

Latest Visitors

Icon   izthrower who needs to do hw when you can play TF2.

Posts I've Made

  1. In Topic: Doubly Linked List

    Posted 30 Mar 2012

    Ok so apperentlly what ive done does work, the only problem is the way you have to define the nodes
    in the unittest program you have to use non existing variables that are defined in the next line,
    Example:
    
        n3 = Node(3,None,n2)
        n2 = Node(2,n3,n1)
        n1 = Node(1,n2,None)
    
    
    


    And the problem is that if i do define them before (example n2=0,n1=0) the zeros pass over when i use the getPre function in the Node class. Any idea on a way around this?
  2. In Topic: Doubly Linked List

    Posted 30 Mar 2012

    
    class Node(object):
    
        def __init__(self, data = None,next = None,pre = None):
            self._data = data
            self._next = next
            self._pre = pre
        
        def getData(self):
            return self._data
    
        def getNext(self, other):
            return self._next
    
        def getPre(self,other):
            return self._pre
    
        def setData(self, data):
            self._data = data
    
        def setNext(self, next):
            self._next = next
    
        def setPre(self,pre):
            self._pre = pre
     
        def __str__(self):
            return str(self._data)
    
        def __repr__(self):
            return "Node(%s, %s)" % (repr(self._data), repr(self._next))
    
        def __eq__(self, other):
            return self._data == other._data and self._next == other._next
    
    #----------------------------------------------------------------------------
    
    class LinkedList(object):
        # (Singly) linked list.
        # Constructed with a dummy node at the begginig of the list.
        # Stores a reference to the dummy node and stores list's length.
    
        def __init__(self):
            # To do: allow a Python list or tuple as a parameter.
            self._length = 0
            self._first = Node(None, None,None)
            self._last = Node(None,None,None
    
        def __len__(self):
            # Special method. Used by built-in function length
            return self._length
    
        def _insertItemAfterNode(self, item, aNode):
            # Private method
            newNode = Node(item, aNode._next)
            aNode._next = newNode
            self._length += 1
    
        def _nodeBeforeIndex(self, index):
            # Private method
            if 0 <= index <= self._length:
                i = -1
                aNode = self._first
                for i in range(index):
                    aNode = aNode._next
                return aNode
            else:
                raise IndexError
    
        def __getitem__(self, index):
            # Special method. Used by rhs indexed expression.
            # ... = mylist[3], print(mylist[3])
            return self._nodeBeforeIndex(index)._next._data
    
        def __setitem__(self, index, item):
            # Special method. Used by lhs indexed expression.
            # mylist[3] = ...
            self._nodeBeforeIndex(index)._next._data = item
    
        def insertItemAtTheFront(self, item):
            self._insertItemAfterNode(item, self._nodeBeforeIndex(0))
    
        def insertItemAtTheEnd(self, item):
            self._insertItemAfterNode(item, self._nodeBeforeIndex(self._length))
    
        def insertItemAtIndex(self, index, item):
            '''Valid range 0 <= index <= length.'''
            self._insertItemAfterNode(item, self._nodeBeforeIndex(index))
    
        def __iter__(self):
            # Special method. Returns iterator.
            return LinkedListIterator(self)
    
        def __repr__(self):
            # Special method. In the absence od __str__ it is used by print.
            plist = []
            for item in self:
                plist.append(item)
            return "LinkedList(%s)" % str(plist)
    
    #----------------------------------------------------------------------------
    
    class LinkedListIterator(object):
    
        def __init__(self, alist):
            self._list = alist
            self._currentIndex = -1
            self._currentNode = self._list._first
    
        def __iter__(self):
            # Any iterator must have __iter__ method that returns self.
            return self
    
        def __next__(self):
            # Any iterator must have __next__ method such that 
            # it possibly raises StopIteration and 
            # if it raises StopIteration than it raises it on even subsequent call.
            if self._currentIndex == self._list._length - 1:
                raise StopIteration
            else:
                self._currentIndex += 1
                self._currentNode = self._currentNode._next
                return self._currentNode._data
            return
    
    
    
    



    This is the code so far ive added all the previous node stuff. Honistly this could be correct but i havent been able to run any tests
    on it to make sure. Any ideas?


    @atraub
    when i read your code i started bowing at my computer then i started getting weird looks from the other people in the computer lab...
  3. In Topic: Input/Output file help

    Posted 29 Mar 2012

    
    for line in infile:
            eval(Line 1) = x 
            celsius = x
            fahrenheit = 9/5 * celsius + 32
            kelvin = celsius + 273.15
            eval(Line 2) = y 
            celsius = y
            fahrenheit = 9/5 * celsius + 32
            kelvin = celsius + 273.15
            print("Iteration #:", "Celsius:",celsius, "Fahrenheit:",fahrenheit,"Kelvin:",kelvin, file=outfile)
    
    
    


    im just curious why you are doing the same thing twice with in this for loop? also you should prolly do x = eval(line) not eval(Line1) = x. This is because you cant set eval(Line1) to anything also, Line1 isnt defined anywhere, and line (i believe) is holding the line from your inputfile. Also you should define x outside the for loop because it will give you an error if you dont.
  4. In Topic: Sum of Numbers

    Posted 29 Mar 2012

    Proly didnt work because you didnt call your main function at the end of the program
  5. In Topic: PROGRAMMING LANGUAGE HELP

    Posted 29 Mar 2012

    Well you should prolly brush up on python 3.x. Not much has changed some TKinterface stuff and print statments
    need perentheses and a few other changes. But i would say start learning java because python hasnt been widely
    accepted yet in the field where as java has.

My Information

Member Title:
D.I.C Head
Age:
22 years old
Birthday:
August 23, 1990
Gender:
Location:
Glenville, NY
Years Programming:
2
Programming Languages:
Java
Python
C
Perl
C++

Contact Information

E-mail:
Private

Friends

Comments

izthrower has no profile comments yet. Why not say hello?