| | |
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
Views: 928 | Replies: 8
| Thread Tools | Search this Thread |
Tag cloud for Python
anti array avogadro beginner builtin clear client code color count csv curved def dictionary dynamic enter examples excel file float format frange ftp function gui heads hints homework import input java lapse line lines linux list lists loop microcontroller mouse multiple mysqldb mysqlquery newb number numbers output parsing path port prime program programming projects py2exe pygame pyopengl pyqt python random raw_input recursion recursive redirect script scrolledtext singleton software sqlite ssh stderr string strings subprocess sum syntax table terminal text thread threading time tkinter tlapse tooltip tuple tutorial twoup ubuntu unicode unix urllib urllib2 variable web-scrape wikipedia windows word wx.wizard wxpython






