Jump to content

HHHEELPP ME (i cant do the task)

here is the task

you get this (array a): -1,2,4,-3,-2,8,-4,5.

you have to make a new array in which the numbers will be placed from smallest to biggest 

 

Link to comment
Share on other sites

Link to post
Share on other sites

Which language?

Link to comment
Share on other sites

Link to post
Share on other sites

19 minutes ago, deXxterlab97 said:

Which language?

c sharp, can you help?

 

Link to comment
Share on other sites

Link to post
Share on other sites

23 minutes ago, Gabe Markman said:

here is the task

you get this (array a): -1,2,4,-3,-2,8,-4,5.

you have to make a new array in which the numbers will be placed from smallest to biggest 

There are more than a few ways to sort the list, but there are two particularly easy ones, that work well for smaller lists. They are called Bubble Sort and Shaker Sort.

In bubble sort for ascending order, you would start with the first value. You will take that value and compare it to the next value in the list. If he next value is smaller, then you need to compare it to the third value in the list. If it is smaller than the third value in the list, you swap the third value with the first value. You then start over with the next first value. When no swaps are made, the list is sorted. There are a few optimizations to make with this, that I will leave you to work out yourself (and also, not all necessary information was given, this is just an overview of the algorithm).

Shaker Sort is exactly like bubble sort, except for we move large values to the right and then we do the same steps going towards the left to move small values to the front. When no swaps are made, the list is sorted. The same optimizations that work with Bubble Sort also work with Shaker Sort.

ENCRYPTION IS NOT A CRIME

Link to comment
Share on other sites

Link to post
Share on other sites

11 minutes ago, Gabe Markman said:

I am allowed to do whatever it takes to to make this program work lol

Quote

ArrayList list = new ArrayList();

list.Add(5);

list.Add(7);

list.sort();

 

             ☼

ψ ︿_____︿_ψ_   

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×