Jump to content

Cannonfodder

Members
  • Posts

    2898
  • Joined

  • Last visited

  • Days Won

    1

Posts posted by Cannonfodder

  1. I'm not a java dude, but is the key input routine you are using designed to return ascii or unicode? If ascii it will always return a value between 0-255. If unicode, it will return a two byte char. Do some googling on code tables for more info. Basically, you press a key and if it goes throug a code table, it gets converted to the character set you are using. So char 13 = this in one char set, and that in another char set. But if no char set is involved or the key routine isn't expected to use them then its ascii..

  2. for more info on this, do a search above on

     

    fstab lilo partition

     

    Basically your boot loader was expecting the partitions to have a certain number. When you made new partitions, you altered the order of the partitions so that partition 1 became partition 2 so on..

     

    Now the lilo.conf file describes where to find each partition. Running lilo program will execute any changes you make to bring things back in line.

     

    You can boot off of Mandrake CD1, hit F1, and type rescue to get to your linux system.

  3. Try sitting down with a piece of paper and a bunch of random single letters. Then make a circle for the first one. That's the head of the list. Let's say its an M. Then grab the next letter, an L. L is less than M so the next node you create is under M and pointed too by the lesserPtr (left side).

     

    The next letter is P. You start at the head of the tree (M). Is greater than M, so you point M's greaterPtr at P. At this point yoiu should have a 3 node tree. M on top and L to the left and P to the right. Looks like a tree.

     

    Now add O. Start with M. O > M right. Follow tree down one on right. O < P. Since P's lesserPtr is NULL, make a new node and point P.lesserPtr at it.

     

    If you play with this, the rules are

     

    start at the top

    follow down, going left or right (lesser or greater) until you hit the end of a branch.

     

    When you are done, you are sorted..

     

    Now retrieve sort. Start at top and go lesserPtr as far as you can go. When you hit NULL in the lesserPtr, you have your first entry. Now backup one ptr. Go right (greater) and then go left again until you hit null. Just repeat that pattern and the retrieved entries should be sorted.

     

    Here is an example of recursion..

     

    function travelTree(pointer myPtr)
     if myPtr.lesserPtr = NULL
        print(myPtr.dataPtr.value)
     else
       travelTree(myPtr.lesserPtr)
       * Now do right pointer
       travelTree(myPtr.greaterPtr)
     end
    endfunc

     

    If you sit with paper and follow this through, you will see that on traveling down a tree on the left (lesser), it keeps calling itself and passing in the lesserptr for the current node until it hits NULL. At this point you have a stack of function calls placed one on top of another like a stack of plates. When it reaches the bottom and prints the value, it will then start returning to the prior calls and each time will execute the next call passing in the greaterPtr.

     

    It's a bit tricky conceptually. Just gotta slow down and sketch it on paper conceptually and once you get the rules it will become easy to program.

  4. One idea is to build a new linked list that co-exists with the original list. The original isn't touched. The new linked list will be sorted. This list will consist totally of pointer objects.

     

    Some sort algorithms you can take a google peek at are btree or quicksort. quicksort is supposely one of the fastest sort algorithms. Be a good exercise for you to learn how to use it.

     

    Now that I'm thinking about this. A sort pointer node would consist of

     

    dataptr

    lesserPtr

    greaterPtr

     

    dataptr would point to the actual data.

     

    lesserPtr would point to a node that contains data that sorts lesser than the current nodes data.

     

    greaterptr would point to a node that contains data that sorts greater than the current nodes data.

     

    Once the tree is built, you can retrieve the sorted data by following a lessPtr to the end and then follow the greaterptr.

     

    Draw it on paper..

     

    If you haven't already, you should look at the concept of recursion. Recursion is when a method calls itself until some condition is met. Recursion and linked lists go hand in hand like butter on toast. They are very useful for traversing linked list since you are basically passing pointer values and continuing until you hit a NULL pointer.

     

    Ask questions if you are not getting this..

×
×
  • Create New...