Why dosent this work? i been trying to learn for hours now

#include
#include
using namespace std;

int main(void)
{
int i, temp;
int count = 0, mode = 0;
const int size = 8;
int num[size], numSorted[8];

cout > num[i];

for (i = 0; i num[i + 1])
{
temp = num[i];
num[i] = num[i + 1];
num[i + 1] = temp;
}
}

cout

Attached: 15563048827.png (680x566, 166K)

Other urls found in this thread:

en.cppreference.com/w/cpp/container/array
twitter.com/SFWRedditGifs

Ah bloo bloo

Practice hello world until you get it

No stack trace?

Are you a moron? He's trying to do bubble sort with a single for loop. It's just an algorithm problem not something a stack trace can fix my good god you are stupider than my dick

are you trying to sort? Me thinks you need to look at how minmax algo looks like

Yes I know it's a bubble sort but for all I know he forgot a semi colon somewhere. It's easier to debug a stacktrace rather than code.

"Doesn't work" in this case isn't a compiler error actually. Just realized that. He needs two for loops lol

Look at the for loop doing the swapping.

Write out an example, and increment 'i' as you go. Look at what happens when it does its final comparison of the value of 'i'.

Your for loops all technically iterate the same number of times. You should iterate up to 'i < size - 1' (not

You get this iteration.
if (num[7] > num[8])

because you fucked up code tags

>for (i = 0; i < size; i++)
but also
>for (i = 0; i

Please no... just use while loops and a flag to see when it's sorted. Also, maybe abstract out the three line swap into a swap(int&,int&) function as they are clearly a beginner and it will be easier to focus on the loop. Should be something like this, but in actual code, not psuedo:

bool notSorted;
while(notSorted==true)
{
notSorted=false;
for(size-1)
if(element and Element+1 need swapping)
{
swap(element, element+1)
notSorted=true;
}
}

That should be more than enough to help you figure it out. If you still don't get it, just drop the course, you'll never make it if you can't even bubble sort. Also, youtube and stackoverflow answers have literally hundreds of solutions to this. Jow Forums is not the right place to ask. There might be a minor error in my algo, I didn't run it obviously, but I would start by trying to understand those parts as that seems to be where you are having trouble...

Attached: 4chan-g-opposite.png (323x249, 114K)

you forgot to include studio

op wants:
>for (i = 0; i < size -1; i++)
because you always compare to numbers at a time. if you do this for each element the last one will check the element against an out of bounds element noob.

Also, OP, you do
>const int size = 8;
>int num[size], numSorted[8];
but also
>cout

Attached: 2018-12-19 07 58 411545159204922.png (782x720, 323K)

You're trying to do a bubble sort, which is O(N^2) with a single iteration, which is O(N). And seeing as you didn't just reinvent computer science as we know it your algorithm is broken

You don't need
>#include
That's for dynamic arrays that change size...

Attached: 2018-12-19 07 57 311545224735173.jpg (500x383, 53K)

There are so many things wrong here as others have pointed out... is this a troll? This has to be a troll? No one is this stupid...

Attached: 3358619 1547858799865.png (540x540, 206K)

>#include
this has to be a joke

And here I thought there were no gore threads on Jow Forums. You proved me wrong. Well done.

en.cppreference.com/w/cpp/container/array

Why are you retards solving her homework?

>No one is this stupid...
Imagine being SO smart to watch, store and share disgusting poorly drawed pedo cartoons.

Some people can't help it. It's reflexive. Something like this is so simple it's solved in seconds and posted before you even realize what you've done. It's like watching someone struggle with single digit arithmetic... It's almost harder to not solve it.

Attached: 2018-12-22 08 29 321545417362970.jpg (800x723, 53K)

Lurk before you post.

Attached: get-out.png (1000x1000, 156K)

You also don't need
>
at the beggining and end

Oof! Needs 7 passes to cover worst case scenario. Smaller values 'bubble up' to the top of the list with each pass Oh well... homework is homework.


// Revison: added variable k because I'm bored (and lazy).
// Note: never use bubble sort for anything other than homework.
// Note2: never use bubblesort outside of community college. Even then, it should remain within the confines of the Liberal Arts.
// War Emergency: Use quicksort to partition down to stacks of 5-8 elements and shellsort each stack in sequence.

#include
#include
using namespace std;

int
main (void)
{
int i, k, temp;
int count = 0, mode = 0;
const int size = 8;
int num[size], numSorted[8];

cout > num[i];

for (k = 0; k < 7; ++k)
{
for (i = 0; i num[i + 1])
{
temp = num[i];
num[i] = num[i + 1];
num[i + 1] = temp;
}
}
}
cout

ugh... using a for loop means this is always worst case....

Allow your fucking arrays first nigger fag

**alloc. Fucking hell auto correct