On Sun, May 8, 2011 at 4:59 PM, iamcreasy <quazir...@gmail.com> wrote: > Hi everybody :)
Welcome! > I am an experienced C++ programmer. Recently I decided to try out > clojure(I have some java experience). My background was C++ for most of the 90's then Java for quite a bit of the 00's so I expect you're finding the hardest part of learning Clojure is adjusting to a functional approach with immutable data? > I read some tutorials of the basics clojure. Now I want to implement > some simple algorithms. Starting with Insertion sort. There are two parts to the problem: * given an item and a sorted list, return a new list with the item inserted in the correct place * given a list of unsorted items, repeatedly perform the first part For the sorted insert: * if the sorted list is empty, return a new list with just the new item * else if the new item is less than the first item in the sorted list, return a new list: (cons new-item sorted-list) * else return a new list: (cons (first sorted-list) (sorted-insert new-item (rest list))) To repeatedly perform the insertion, try a loop with three variables: next item to insert, remaining items to insert, sorted list so far... Hope that helps you get started? -- Sean A Corfield -- (904) 302-SEAN An Architect's View -- http://corfield.org/ World Singles, LLC. -- http://worldsingles.com/ Railo Technologies, Inc. -- http://www.getrailo.com/ "Perfection is the enemy of the good." -- Gustave Flaubert, French realist novelist (1821-1880) -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en