Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
| 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
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.



 
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
 
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.

 
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
 
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

 
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.





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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.