Trees

Discussion of Common Lisp
Mercfh
Posts: 17
Joined: Tue Mar 30, 2010 3:39 pm
Location: Miami,FL

Re: Ternary Trees

Post by Mercfh » Sat Apr 03, 2010 8:10 am

Ramarren wrote:
Mercfh wrote:U say the nodes can store up to 2 values? why 2 values. and can it be any value?
It says so in the very text of assignment you quoted!
Each node in a non-empty ternary tree is allowed to have either 1 or 2 values.
Seriously, try reading it. Doing a task is much simpler once you actually read the description. Sorry if this sounded snarky, but, well...
Ok I did some more research of Terenary trees and it makes more sense. Dont worry u dont sound snarky I know it can be frustrating lol but this is my first time using lisp so It's a bit confusing. But i got the atom reading part done at least yay.

I just have a tad bit of Dyslexia so when I read stuff (sometimes even 15 times) I wont exactly "get it" always because words do not always come together in the same way. (it makes coding a complete pain ahahah)

Code: Select all

(defun read-setup (filename)
(with-open-file (stream filename)
    (loop for line = (read stream nil 'end)
          until (eq line 'end)           
          do (print (list (coerce line 'integer)
 )     
     )     
     )
)
)

I know it's small but this should work right? putting them into a single list unless there is a better way.

Piotr
Posts: 2
Joined: Fri Apr 02, 2010 8:05 pm
Location: Canada

Re: Ternary Trees

Post by Piotr » Sat Apr 03, 2010 8:29 am

Mercfh wrote:
Ramarren wrote:
Mercfh wrote:U say the nodes can store up to 2 values? why 2 values. and can it be any value?
It says so in the very text of assignment you quoted!
Each node in a non-empty ternary tree is allowed to have either 1 or 2 values.
Seriously, try reading it. Doing a task is much simpler once you actually read the description. Sorry if this sounded snarky, but, well...
Ok I did some more research of Terenary trees and it makes more sense. Dont worry u dont sound snarky I know it can be frustrating lol but this is my first time using lisp so It's a bit confusing. But i got the atom reading part done at least yay.

I just have a tad bit of Dyslexia so when I read stuff (sometimes even 15 times) I wont exactly "get it" always because words do not always come together in the same way. (it makes coding a complete pain ahahah)

Code: Select all

(defun read-setup (filename)
(with-open-file (stream filename)
    (loop for line = (read stream nil 'end)
          until (eq line 'end)           
          do (print (list (coerce line 'integer)
 )     
     )     
     )
)
)

I know it's small but this should work right? putting them into a single list unless there is a better way.

That implementation will work I think for an assignment like this. you are basically going to want to put the Atoms as they are called in an initial list. Then make the initial Tree parameters. You will need an insert function and then a print function. Although the default print in lisp will do the printing you will need.

Jasper
Posts: 209
Joined: Fri Oct 10, 2008 8:22 am
Location: Eindhoven, The Netherlands
Contact:

Re: Ternary Trees

Post by Jasper » Sun Apr 04, 2010 6:36 am

gugamilare wrote:Or use logbitp, which is already in ANSI CL.
I did look for such a function, but i couldn't find it.. I think i am probably still missing a bunch of such functions... I'll try look at topical references next time.

gugamilare
Posts: 406
Joined: Sat Mar 07, 2009 6:17 pm
Location: Brazil
Contact:

Re: Ternary Trees

Post by gugamilare » Sun Apr 04, 2010 8:09 am

Jasper wrote:
gugamilare wrote:Or use logbitp, which is already in ANSI CL.
I did look for such a function, but i couldn't find it.. I think i am probably still missing a bunch of such functions... I'll try look at topical references next time.
Try inspecting all the functions which begin with "log", ANSI CL have all sorts of bitwise operations. Take a look also at ldb and dpb.

Mercfh
Posts: 17
Joined: Tue Mar 30, 2010 3:39 pm
Location: Miami,FL

Re: Ternary Trees

Post by Mercfh » Wed Apr 07, 2010 12:44 am

Thanks everyone for your help. I FINALLY understand how the tree works.

It's pretty simple when I got down to it. I got a create-tree function set up. and it seems to work no errors so far. just understanding the concept was the hardest part.
I also got an insert function. my print function isn't working right now. it prints.........stuff, but it's all out of whack, but I got plenty of time to figure that out.

Just wanted to thank everyone :) for helping me understand it

Post Reply