83.2k views
4 votes
Hi everyone! I was wondering if any of you want to help me with a computer science problem I have for one of my classes. I do not understand how to do it which is why I ask.

Here is the problem: Write an algorithm for placing a set of pencils in order from largest to smallest (left to right).

I learned other sorting algorithms but I don't quite understand how to implement them into my own algorithm.

Thanks.

User Fenix
by
7.7k points

1 Answer

0 votes

Answer:

Use bubble sorting

Here is an example program I made:

for(int i = 0; i < length; i++){

for(int j = 0; j < length; j++){

if(j != length - 1){

if(input[j] > input[j + 1]){

storeVar = input[j];

input[j] = input[j+1]; //storeVar2;

input[j+1] = storeVar;

}

}

}

User McShaman
by
8.2k points