| | |
C to Python Translation anyone?
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Oct 2008
Posts: 20
Reputation:
Solved Threads: 0
I've been reading an article but the code is written in C language which I don't get at all...
The code is:
Someone please translate it to python...
The code is:
Python Syntax (Toggle Plain Text)
void traverse(Tptr p) { if (!p) return; traverse(p->lokid); if (p->splitchar) traverse(p->eqkid); else printf("%s/n", (char *) p->eqkid); traverse(p->hikid);
Someone please translate it to python...
•
•
Join Date: Oct 2008
Posts: 45
Reputation:
Solved Threads: 6
python Syntax (Toggle Plain Text)
def traverse(p): try: p except NameError: traverse(p=lokid) if (p==splitchar): traverse(p=eqkid) else: print p traverse(p=hikid)
I think this is what you would want... someone correct me though... I thought it was good, but then I reread it and I'm a little drunk...
What I am confused about is, two lines into the function, it says restart the function...
Last edited by tyincali; Oct 30th, 2008 at 12:06 am.
I wish I had something cool to put here...
•
•
•
•
I've been reading an article but the code is written in C language which I don't get at all...
The code is:
Python Syntax (Toggle Plain Text)
void traverse(Tptr p) { if (!p) return; traverse(p->lokid); if (p->splitchar) traverse(p->eqkid); else printf("%s/n", (char *) p->eqkid); traverse(p->hikid);
Someone please translate it to python...
python Syntax (Toggle Plain Text)
def traverse(p): if not p: return traverse(p.lokid) if p.splitchar: traverse(p.eqkid) else: print(p.eqkid) traverse(p.hikid)
•
•
Join Date: Oct 2008
Posts: 45
Reputation:
Solved Threads: 6
yes, but because of the
traverse(p->lokid); two lines into the function, it restarts itself over and over until the end when the fact that p is not defined forces a return. There is no way for it to get to the code after the second line, because it always restarts itself. I wish I had something cool to put here...
You must think recursively! These calls are all stacked so once it traverses to the outer-most or lower-most children, p becomes none, so it returns. When it returns, the function that called it can then proceed past that
You see this thing travels to all of the children, and then starts doing what it needs to do. And it looks like it's a tertiary (triary? I'm not sure which word is correct) search as opposed to binary search.
traverse(p->lokid) call.You see this thing travels to all of the children, and then starts doing what it needs to do. And it looks like it's a tertiary (triary? I'm not sure which word is correct) search as opposed to binary search.
![]() |
Similar Threads
- Starting Python (Python)
- Assembly or C++ for a Beginner? (IT Professionals' Lounge)
- hello! :) (Community Introductions)
- Convert from JAVA/JSP to Python (Python)
- iPOD and pypod on Umlauts (Python)
Other Threads in the Python Forum
- Previous Thread: probel with pyExcelerator
- Next Thread: importing PYD files
| Thread Tools | Search this Thread |
accessdenied apache application argv array beginner book change color converter countpasswordentry curved dan08 dictionary dynamic edit editing enter examples excel file filename float format function gui homework import inches input java keyboard lapse library line lines linux list lists loop microphone mouse movingimageswithpygame mysql mysqlquery newb number numbers numeric output parameters parsing path phonebook plugin port prime programming projects py2exe pygame pyopengl pysimplewizard python random recursion redirect remote reverse scrolledtext session simple smtp software sprite statictext string strings syntax table tennis terminal text thread threading time tkinter tlapse trick tuple tutorial ubuntu unicode unit urllib urllib2 variable windows wordgame wxpython






