VAR-solutions / Algorithms

A repository of different Algorithms and Data Structures implemented in many programming languages.
https://var-solutions.github.io/Algorithms/
MIT License
764 stars 1.01k forks source link

in Insertion-sort.c : the user can access to other blocks of memory #1628

Open wassim31 opened 3 years ago

wassim31 commented 3 years ago

int n, array[1000], c, d, t; printf("Enter number of elements\n"); scanf("%d", &n);

the compiler is allocating 4000 bytes in the stack , then the program asks the user how many elements he wants.. instead of that , it's better to ask the user how many elements he wants first ( upper-bounded ) , do dynamic memory allocation on the heap segement using standard library function void * malloc( size_t memorySize );