Problem with Insertion Sort via /r/learnprogramming

Problem with Insertion Sort

What's wrong with my algorithm? It's only working with positive numbers

#include <stdio.h> int main(void) { int vSize, i, j; int tmp; printf("Vector size: "); scanf("%d", &vSize); int numVector[vSize]; for(i=0; i < vSize; i++) { scanf("%d", &numVector[i]); } for(i=0; i < vSize; i++) { j = i; while(j >=0 && numVector[j] < numVector[j-1]) { tmp = numVector[j-1]; numVector[j-1] = numVector[j]; numVector[j] = tmp; --j; } } puts("sorted"); for(i=0; i < vSize; i++) { printf("numVector[%d] = %d\n", i, numVector[i]); } } 

Submitted July 13, 2017 at 06:18PM by I-Trey
via reddit


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s