Skip to content

Explore various sorting algorithms implemented in C within this repository. Each algorithm, such as Bubble Sort, Insertion Sort, Selection Sort, and Quick Sort, is meticulously crafted in separate C files. Witness these algorithms in action as they sort arrays or linked lists, with printed outputs after each step.

License

Notifications You must be signed in to change notification settings

hima890/sorting_algorithms

Repository files navigation

logo

Sorting Algorithms

This repository contains implementations of various sorting algorithms in C. Each sorting algorithm is implemented in a separate C file and is tested with example arrays or linked lists.

Table of Contents

General Requirements

  • Code is written in C language.
  • All code is compiled on Ubuntu 20.04 LTS using gcc.
  • The code follows the Betty style.
  • Global variables are not allowed.
  • Each C file contains no more than 5 functions.
  • The standard library is not used unless specified otherwise.
  • Header files are included with include guards.
  • A README.md file is included at the root of the project folder.
  • All header files contain prototypes of functions.
  • List and array sizes less than 2 are not sorted.
  • There is one project repository per group.

Sorting Algorithms

Bubble Sort

  • Prototype: void bubble_sort(int *array, size_t size);
  • Sorts an array of integers in ascending order using the Bubble sort algorithm.
  • Prints the array after each swap.

Insertion Sort

  • Prototype: void insertion_sort_list(listint_t **list);
  • Sorts a doubly linked list of integers in ascending order using the Insertion sort algorithm.
  • Prints the list after each swap.

Selection Sort

  • Prototype: void selection_sort(int *array, size_t size);
  • Sorts an array of integers in ascending order using the Selection sort algorithm.
  • Prints the array after each swap.

Quick Sort

  • Prototype: void quick_sort(int *array, size_t size);
  • Sorts an array of integers in ascending order using the Quick sort algorithm with the Lomuto partition scheme.
  • Prints the array after each swap.

Big O Notations

For each sorting algorithm, the time complexity in the best case, average case, and worst case is provided in separate files named 0-O, 1-O, 2-O, and 3-O, respectively.

Usage

To test each sorting algorithm, compile the corresponding C files along with the main file and execute the compiled program.

For example:

gcc -Wall -Wextra -Werror -pedantic -std=gnu89 0-bubble_sort.c 0-main.c print_array.c -o bubble_sort
./bubble_sort

### Authors
Ibrahim Hanafi

About

Explore various sorting algorithms implemented in C within this repository. Each algorithm, such as Bubble Sort, Insertion Sort, Selection Sort, and Quick Sort, is meticulously crafted in separate C files. Witness these algorithms in action as they sort arrays or linked lists, with printed outputs after each step.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published