how do you like my array sorter :3
#include
int sorted(int numbers[], int numbercount)
{
bool check(false);
int i (0);
while (true)
{
if (i == numbercount)
{
i = 0;
check = true;
}
if (numbers[i] > numbers[i+1])
return i;
if (numbers[i]
How do you like my array sorter :3
>int i(0)
fuck you
...
WHAT'S WRONG
>break
Looks like somebody just got finished doing their CS I homework
I'm self learning (ie reading a book I downloaded)
:(
>const int numbercount = sizeof(numbers)/ sizeof(numbers[0]) - 1;
why name this variable 'numbercount'
you are lying and making the whole program confusing as shit. it's not number count. it's the number count minus one.
looks like a hack you spent 20 minutes trying to figure out switching numbers around till something worked.
also you are over-complicating things. here is a simplified version which achieves the same result:
#include
int main()
{
int numbers[] = {10,9,8,7,6,5,4,3,2,1};
const int count = sizeof(numbers) / sizeof(numbers[0]);
for(int i=0; i
Keep up, grandpa
#include
#include
#include
#include
int main(int argc, char const *argv[]) {
auto arr = std::experimental::make_array(10, 9, 8, 7, 6, 5, 4, 3, 2, 1);
std::sort(arr.begin(), arr.end());
// if sorted, print items, which I know it is
if (std::is_sorted(arr.begin(), arr.end())) {
for (auto &i : arr) {
std::cout
Why not
std::array arr = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
?
>He counts his array items
break is best command ever fuck you
Nice bubblesort.
op here I made a new one that seems better
#include
int main()
{
int array[] = {1,-201,1,-1,1,0,69};
const int maxIndex = sizeof(array)/sizeof(array[0])-1;
for(int currentIndex(0); currentIndex < maxIndex; currentIndex++)
{
int smallIndex(currentIndex);
for (int currentIndex2(maxIndex); currentIndex2 > currentIndex; currentIndex2--)
if (array[currentIndex2] < array[smallIndex])
smallIndex = currentIndex2;
int swapup(array[smallIndex]);
int swapdown(array[currentIndex]);
array[smallIndex] = swapdown;
array[currentIndex] = swapup;
}
for(int currentIndex(0); currentIndex
Why are you torturing yourself?
am I doing this very poorly?
No, you should not be sorting arrays yourself in the first place.
You shouldn't be using legacy (C-style) arrays either
I'm just practicing and playing around man
>you shouldn't learn sorting algorithms
Exactly. Don't tell me you learn how std::cout.operator
isn't that like memorize a mathematical formula without understanding the underlying logic behind it?
you don't learn how to overload operators?
How do you even make a program?
stop sorting arrays
only if varg tells me not to
stop
>you don't learn how to overload operators?
Yes I did. What I chose not to learn is how libc++ implemented std::cout.operator
>goys check my sort
CLRS page 18 has a sort that is about 20 times cuter than yours
for j = 2 to A.length
key = A[j]
i = j - 1
while i > 0 and A[i] > key
A[i + 1] = A[i]
i = i - 1
A[ i + 1] = key
fuck YOU
but look at it
so cute, and insertion sort is still pretty good in a lot of cases
i even have a gif which looks like it might be a sort comparison
I'm just messin