Go Back   Science Forums
View Single Post
Old 04-24-2009   #5 (permalink)
phillip1882's Avatar
phillip1882
Thinking


Location:
florida
 
phillip1882 is a glorious beacon of lightphillip1882 is a glorious beacon of lightphillip1882 is a glorious beacon of lightphillip1882 is a glorious beacon of light
 



Not Ranked  0 score     
Re: programming for beginners

the sorting one should be fairly simple, here's one of my personal favorites.
Code:
def quicksort(left,right,valarray):
   a= left
   b = right-1
   while a != b:
      if valarray[a] <=valarray[a+1]:
        temp = valarray[a]
        valarray[a] = valarray[a+1]
        valarray[a+1] = temp
        a= a+1
      else:
        temp = valarray[a+1]
        valarray[a+1] =valarray[b]
        valarray[b] = temp
        b = b-1
   print valarray
   if a+1<right-1:
      quicksort(a+1,right,valarray)
   if a > left+1:
      quicksort(left,a,valarray)
this basically takes the first element, places all elements smaller than it on the right, all elements greater than it on the left, and the recursively sorts the left and right

well that's basically the guts of programming. there's still a lot to learn of course, such as object oriented programming, but this is beyond the scope of a beginner tutorial. if you would like to hone your skills, the website topcoder.com has hundreds of practice problems ranging from easy to advanced. if you need more help, there's plenty of stuff online for more information.
Reply With Quote
 
» Advertisement
» Current Poll
Who's the sexiest man alive? Johnny Depp or Robert Pattinson?
Johnny Depp - 27.27%
3 Votes
Robert Pattinson - 0%
0 Votes
Someone else (please specify) - 45.45%
5 Votes
I'm too macho to think a guy is sexy - 27.27%
3 Votes
Total Votes: 11
You may not vote on this poll.


All times are GMT -8. The time now is 09:22 AM.

Hypography?

Hypography [n.]: A combination of "hyperlink" and "bibliography" - ie, a list of links to electronic documents. Comparable to discography and bibliography, but not cartography.

We have been online since May 2000, and aim to be the best place to find and share science-related content of all kinds.

Share the love!

Please add more science to your life. Use our RSS feeds on your blog, your portal, or your favorite feedreader!


Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright © 2000-2009 Hypography
Part of the Hypography - Science for Everyone Network