Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 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 August 15th, 2006, 04:51 AM
Authorized User
Points: 287, Level: 5
Points: 287, Level: 5 Points: 287, Level: 5 Points: 287, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2006
Location: Stone, California, Malaysia.
Posts: 58
Thanks: 0
Thanked 0 Times in 0 Posts
Default One dimension array.

Can anybody show me, how to code for searching the biggest or smallest number in one dimension array.

number[i] = 1,3,2,4,5,7,9,8,6,10.

Thank you.



Reply With Quote
  #2 (permalink)  
Old August 15th, 2006, 02:16 PM
Authorized User
 
Join Date: Aug 2006
Location: , , Netherlands.
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Wenggo,

Below one of my many array functions. I don't know if .NET Framework contains one at least I could not find one. Use this at your own risk. I never tested it extensively but it should work. Based on the algorithm you can write your own version, maybe more effective than mine. As so for searching the min. value. And of course write some error handling for it.

In the past i wrote three versions and this should be the correct one. If not let me know.

    public int f_array_max_int (int[] p_array)
    {
        int ArrayLength = p_array.Length;

        int MaxValue = p_array[0];

        for (int i = 0; i < ArrayLength; i++)
        {
            foreach (int TempValue in p_array)
            {
                if (TempValue >= MaxValue)
                {
                    MaxValue = TempValue;
                }
            }

            Array.Reverse(p_array);

            Array.Resize(ref p_array, ArrayLength-i-1);

            Array.Reverse(p_array);
        }
        return MaxValue;
    }

Regards,
.NETamateur
Electrical Engineer
Reply With Quote
  #3 (permalink)  
Old August 15th, 2006, 02:20 PM
Authorized User
 
Join Date: Aug 2006
Location: , , Netherlands.
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Since you are busy with arrays, can you help me with http://p2p.wrox.com/topic.asp?TOPIC_ID=48359? It is not been answered yet.

Reply With Quote
  #4 (permalink)  
Old August 17th, 2006, 04:30 PM
Authorized User
 
Join Date: Aug 2006
Location: , , Netherlands.
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Wenggo,

These are my revised versions of finding min. and max. values in an array. You can better use these ones. The performance is much better than previous one.

Find max. value in array:

   public double f_array_max (double[] p_array)
   {
      Array.Sort(p_array);
      return p_array[p_array.Length-1];
   }

Find min. value in array:

   public double f_array_min (double[] p_array)
   {
      Array.Sort(p_array);
      return p_array[0];
   }

Regards,
.NETamateur
Electrical Engineer
Reply With Quote
  #5 (permalink)  
Old August 18th, 2006, 02:34 AM
Authorized User
Points: 287, Level: 5
Points: 287, Level: 5 Points: 287, Level: 5 Points: 287, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2006
Location: Stone, California, Malaysia.
Posts: 58
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you buddy...

For (i=0; i > 10; i++) {
   For (u=1; u > 10; u++) {

temp = matrix[i]
   matrix[i] = matrix[j]
   matrix[j] = temp

Reply With Quote
  #6 (permalink)  
Old August 18th, 2006, 02:39 AM
Authorized User
Points: 287, Level: 5
Points: 287, Level: 5 Points: 287, Level: 5 Points: 287, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2006
Location: Stone, California, Malaysia.
Posts: 58
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry...

For (i=0; i > 10; i++) {
   For (u=1; u > 10; u++) {
   if (matrix[i] > matrix[u]){
   temp = matrix[i]
   matrix[i] = matrix[u]
   matrix[u] = temp

I try like this...from our friend ideas.

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
need help to create my country calendar dimension dbayona SQL Server 2000 1 July 4th, 2007 12:54 AM
Dimension Hierarchies Not Working orangepower SQL Server 2005 1 December 14th, 2006 03:41 PM
Date Dimension mtullock SQL Server 2000 5 August 31st, 2006 09:33 AM
SQL OLAP Dimension Writeback ripahoratiu SQL Server 2000 0 October 24th, 2003 02:43 AM



All times are GMT -4. The time now is 11:21 AM.


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