Coder Social home page Coder Social logo

algorithms's People

Contributors

antidigest avatar antriksha avatar evamy avatar

Watchers

 avatar  avatar

algorithms's Issues

A Small Suggestion

Hey!
If I may, I have a little suggestion.
It is considered best practice, when writing code, to implement the algorithm in a generic form, i.e., your program should run regardless of the size of the array (in this case). For instance, your for loop (in Insertion Sort) uses the condition j < 6 (because the length of the array you used is 6). This program will break if I use any array which doesn't have the length 6.

I know that you have understood the algorithm by heart and just want to demonstrate this fact, but get in the habit of writing generic code from day 1. Believe me, its going to do wonders for you in future!

(for example, take the Insertion Sort Algo, implement it inside a separate function (lets call it insertion_sort ()) which accepts an array as an argument (or a pointer to the array plus its length). This way, I can use any sort of array (with any primitive data type like char, float, int, etc.) of any size, simply call a function from main () and poof! Its done!).
This means all I have to write in my file is:

include <stdio.h>

//COPY YOUR FUNCTION DEFINITION
int main () {
int A [] = {-2, 893, 89, 29, 189};
length = sizeof (A) / sizeof (A [0]);
insertion_sort (A, length);
//logic to print the sorted array

return (0);
}

Try to make it as smooth as possible for someone else who might want to use your code.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.