Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

C# - Dropping Highest And Lowest Values In Array


  • Please log in to reply
2 replies to this topic

#1 TBen018

TBen018

  • Members
  • 17 posts
  • OFFLINE
  •  
  • Local time:08:11 AM

Posted 18 November 2007 - 04:00 PM

Hello all, just a quick question.

Is there any way (or command) to take the highest and lowest values out of an array and drop them, then resize the array to account for the 2 less spaces?
Let me know what you think, or possibly somewhere I can find the answer. I've tried looking over google, but cant find anything.

~Taylor

BC AdBot (Login to Remove)

 


#2 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:06:11 AM

Posted 18 November 2007 - 04:44 PM

Yes. Keep two variables called indexHi and indexLo, and two variables called hi an lo; Iterate through the array. If the number is lower than lo, save that number in lo, and the index in indexLo. If the number is higher than hi, save the number in hi, and save the index in indexHi. When you are done, you will have the index of the highest and lowest numbers.

Arrays do not have methods for removing elements or resizing, so you just create a new array and copy all of the elements into it except for ones at the index held by indexHi and indexLo.

#3 TBen018

TBen018
  • Topic Starter

  • Members
  • 17 posts
  • OFFLINE
  •  
  • Local time:08:11 AM

Posted 18 November 2007 - 06:03 PM

I tried your method, but couldn't get data from 1 array to the next!

public void rewriteMethod()
		{
			int count=0;
			int countTwo=0;
			foreach (int i in arrayScores)
			{
				if(arrayScores[count]!=currentArrayValue||arrayScores[count]!=currentArrayValueL)
				{
					arrayTwoScores[countTwo]=arrayScores[count];
					count++;
					countTwo++;
				}//end if
				else if(arrayScores[count]==currentArrayValue||arrayScores[count]==currentArrayValueL)
				{
					count++;
				}//end if

			}//end foreach
		}//end rewriteMethod


My initial array had 9 spaces, and depending on the index position of the High Low values, I want it to skip a cell in my first array but not my second. CurrentArrayValue(L) is my index position of High and Low. Does that seem like it would work to you?


EDIT: I'm trying to compare index positions, but I'm not sure on how to code that. The way I have it, is it is comparing the data within each cell with the index number of the Highest/Lowest number.

Any ideas?

Edited by TBen018, 18 November 2007 - 08:57 PM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users