Created
May 31, 2017 11:16
-
-
Save ohmree/dac78b36b736a71dc9a423d10b9509cc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "raylib.h" | |
void swap(int* num1, int* num2) | |
{ | |
int temp = 0; | |
temp = *num2; | |
*num2 = *num1; | |
*num1 = temp; | |
} | |
int main() | |
{ | |
int temp = 0; | |
int arr1[10]; | |
for (int i = 0; i <= 10; i++) | |
{ | |
arr1[i] = GetRandomValue(0, 1000); | |
} | |
for (int i = 0; i <= 10; i++) | |
{ | |
if (i == 10) break; | |
if (arr1[i] > arr1[i+1]) | |
{ | |
swap(*arr1[i], *arr1[i + 1]); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This code has undefined behavior. You are accessing out of bounds of
arr1
. (The<
operator exists.) And your code doesn’t actually sort anything (if it even compiled).