Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Other Programming > Other Programming Languages
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Other Programming Languages If you have a coding issue to discuss about another language that really isn't provided for in any other forum here (not ASP.NET C#, C++, VB, PHP, JavaScript, Python, Java, Perl, Applescript, XML or any of the other forum topics we have), post it here. Enough discussion on a language we don't have covered could prompt a new forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Other Programming Languages section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 31st, 2006, 12:30 PM
Authorized User
 
Join Date: Feb 2005
Location: hyderabad, Andhara Pradesh, India.
Posts: 91
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to ashokparchuri Send a message via Yahoo to ashokparchuri
Default How to get least value numbers in a sorted array?

Hi,

   I had a doubt that if we have an sorted array with some numbers like 45,54,65,34,34,23,78. How can we get the least umbers in this arrray?
Please reply me as soon as possible.

Thanks-Ashok
Reply With Quote
  #2 (permalink)  
Old June 24th, 2006, 09:25 AM
Authorized User
Points: 312, Level: 6
Points: 312, Level: 6 Points: 312, Level: 6 Points: 312, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2006
Location: Orpington, Kent, United Kingdom.
Posts: 73
Thanks: 1
Thanked 1 Time in 1 Post
Default

Ashok, it will depend on your language very much, but in principle, you would code for a 'bubble sort', which means you look at each elememt in the array in turn and compare it to the other elements. Storing the lower number in a variable on each comparison, until eventually the smallest number is stored in the variable. Post again with more detail, I write in Visual Basic.liamfitz.

Reply With Quote
  #3 (permalink)  
Old December 1st, 2006, 03:17 PM
Registered User
 
Join Date: Dec 2006
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

in javascript/perl/php slight difference in declaration of variables but i will do it in js. Per suggested previously.

var lowest_num=0;
for(var i=0;i<array_name.length;i++){
 if(array_name.length != i){ // no need to look at last
  var temp_holder = array_name[i];
  var temp_holder2 = arrau_name[i+1] // look one ahead
  if(temp_holder < temp_holder2){
    lowest_num=temp_holder;
  }
  else{
   lowest_num=temp_holder2;
  }
 }
}

should be fairly close, if not working

now if you wanna build a numerically sorted array, i suggest you look at "push / pop" method

Reply With Quote
  #4 (permalink)  
Old December 5th, 2006, 09:25 AM
Friend of Wrox
Points: 1,515, Level: 15
Points: 1,515, Level: 15 Points: 1,515, Level: 15 Points: 1,515, Level: 15
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2003
Location: Oxford, , United Kingdom.
Posts: 488
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Most languages have built in sorting, which works well in the majority of cases - you should use these. If keeping the information in a sorted order is important you may want to consider using a data structure other than an array.

Anyhow, here's a couple of snippets that find the lowest number in an array.

Here's a perl version:
Code:
my @unsorted = (34, 69, 12, 67, 21, 9, 78, 478327);
my @sorted = sort {$a <=> $b} @unsorted;
print "$sorted[0]\n";
Here's a ruby version:
Code:
arr=[34, 69, 12, 67, 21, 9, 78, 478327]
p arr.sort.first
Cheers

--
Don't Stand on your head - you'll get footprints in your hair
                                           http://charlieharvey.org.uk
                                              http://charlieharvey.com
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Position of sorted nodes tall rog XSLT 5 July 9th, 2007 05:59 PM
Grouped and sorted table row numbers ADenny XSLT 1 April 24th, 2006 10:06 AM
fillin array with letters from a to Z and numbers sajid C# 10 May 3rd, 2005 03:38 PM
sorted table crmpicco Javascript How-To 0 March 17th, 2005 10:29 AM
Dataset does not get sorted correctly Imar ADO.NET 2 December 29th, 2003 04:49 PM



All times are GMT -4. The time now is 10:22 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.