473,763 Members | 5,396 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What is wrong with my colour sort?

1 New Member
i am trying to create a list of array with random numbers and use the colour sort to sort them to let the negative number on LHS zero in middle and positive number on RHS
and print out the sorted array
but it doesn't work and i have no idea what is wrong with it
can some one please help me thanks


using System;
using System.Collecti ons.Generic;
using System.Text;

namespace NegativebeforeP ositive

{
static class Program
{
private static int[] ArrayAdd(int[] array, int element)
{
int newLength = array.Length + 1;
int[] temp = new int[newLength];
Array.Copy(arra y, temp, array.Length);
temp[temp.Length - 1] = element;
return temp;
}

public static void NegbeforePos(in t[] array)
{
int negative= array[0];
//int zero = array[0];
//int postive = array[0];
int i=0;
int j=array.Length-1;
int temp=0;

while (i <= j)
if (array[i] < 0)
{
array[i] = negative;
i = i + 1;
}
else if
(array[i] > 0)
{

array[j] = temp;
array[i]=array [j];
array[i] = temp;
j = j - 1;
} Console.WriteLi ne("arrays are = "+ array);


Console.ReadLin e();
}
static void Main(string[] args)
{


Random RandomClass = new Random();
DateTime StartTime = DateTime.Now;
int[] array = { };
for (int d = 0; d < 100; d++)
{
int RandomNumber = RandomClass.Nex t(-100, 100);
array = ArrayAdd(array, RandomNumber);
// Console.WriteLi ne("initial no=" + array[j]);
//NegbeforePos max = new NegbeforePos();
NegbeforePos(ar ray);
DateTime StopTime = DateTime.Now;
TimeSpan duration = StopTime - StartTime;
Console.WriteLi ne("millisecond s = " + duration.TotalM illiseconds);

} Console.ReadLin e();
}
}
}
Aug 25 '07 #1
2 1465
weaknessforcats
9,208 Recognized Expert Moderator Expert
This looks like C#.

I ma moving this to the .NET forum.
Aug 25 '07 #2
kenobewan
4,871 Recognized Expert Specialist
Are you getting any errors? Have you tried debuging the code?
Aug 26 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

7
1892
by: Hostile17 | last post by:
I'm trying to arrive at a kind of "industry standard" or "best practice" approach to CSS for a policy document aimed at developers, but not necessarily very experienced developers. What does the CIWAS community think is the best way to go about styling documents for maximum compatibility/minimum problems with old browsers. We have a range of people currently using a range of techniques, i.e.
86
7798
by: Michael Kalina | last post by:
Because when I asked for comments on my site-design (Remember? My site, your opinion!) some of you told me never to change anything on font-sizes! What do you guys think of that: http://www.clagnut.com/blog/348/ I hope that's going to be a good discussion! Michael
11
30974
by: Angus Comber | last post by:
Hello I want to create a lookup table where I can store string keys: For example: 192.168.0.1 -> Purple 192.168.0.2 -> Blue 192.168.0.3 -> Red
9
1342
by: Karlo Lozovina | last post by:
Here is it: --- class Human: def __init__(self, eye_one, eye_two): self.eye_one = eye_one self.eye_two = eye_two class Population: def __init__(self):
11
2494
by: Hugh Janus | last post by:
OK, this is driving me crazy! As far as I can tell it should work. It compiles fine. I am saving the fore and back colour of a RTB to the registry like this: Srx.SetValue("ForeColour", Console.ForeColor.ToArgb.ToString) Srx.SetValue("BackColour", Console.BackColor.ToArgb.ToString) Then, I try to read the colours back in at runtime and change the
7
2231
by: Mike Barnard | last post by:
It's a simple test... VERY SIMPLE. But... In an external stlyesheet some attributes don't show. With the same styles cut and pasted to the test internally it works as expected. Anyone tell me why? Its probably sooooooo obvious, but it is 1.19 am! Thanks. www.thunderin.co.uk/
39
3087
by: VidTheKid | last post by:
THE PROBLEM The % symbol is too vague when defining dimensions in CSS and HTML. It can relate to an inherited value, a measure of the containing element (which can differ between box models) or for background image placement, the size of the element minus the size of the image. A SOLUTION There should be new %-like units defined in CSS to specify what the measurement is a percentage of. These take the form of the % sign and one or...
0
1040
by: Tim Marshall | last post by:
Wondering if anyone knows if there is some setting in Adobe Acrobat 6.0 that controls colour settings? With an older version of Acrobat I used to use with Access 97, I had no problem with graphs being printed from a form coming out in the pdf document in the colours displayed on the on screen form. Now with Acrobat 6.0 and Access 2003, the pdf is always black and white. I've tried changing my default printer (all the printers I have...
2
1297
by: jakeruston | last post by:
Hi, I have coded this and it is coming up with hundreds of errors. What is wrong with this anyway? #include <iostream> #include <string> using namespace std; using std::cout;
0
9387
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10148
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10002
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9938
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8822
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7368
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5270
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3917
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3528
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.