Skip to content

Latest commit

 

History

History
59 lines (43 loc) · 3.06 KB

README.md

File metadata and controls

59 lines (43 loc) · 3.06 KB

C CI Codacy Badge cppcheck-action Valgrind

The project was made as part of the Coding Interview University course.

Linear data structures using C

Implementation of classic linear data structures

Vector (Dynamic array)

  • vector_get - returns item at given index, NULL if index out of bounds
  • vector_push_back - adds an element to the end
  • vector_is_empty
  • vector_capacity - number of items it can hold
  • vector_size - number of items
  • vector_resize // private function
  • vector_delete_by_index - delete item at index, shifting all trailing elements left
  • vector_delete_by_value - looks for value and removes index holding it (even if in multiple places)
  • vector_insert_by_index - inserts item at index, shifts that index's value and trailing elements to the right
  • vector_free - frees memory of vector

Search functions

  • vector_find - implementation linear search
  • vector_binary_search - implementation binary search

Sort functions

  • vector_bubble_sort - implementation bubble sort
  • vector_insertion_sort - implementation insertion sort

Higher-order functions

  • vector_foreach - applies a function to each element of the array
  • vector_filter - add to a new array elements whose predicate returns true
  • vector_fold - converts a vector to a single value
  • vector_any - return true if at least one element of an iterable is true else false

Stack (using linked list)

  • stack_push - inserts a new element at the top of the stack, above its current top element
  • stack_pop - removes the element on top of the stack, effectively reducing its size by one
  • stack_peek - returns the next character in the input sequence, without extracting it
  • stack_size - returns count of elements
  • stack_is_emtry = returnы 1 if stack is empty, else returns 0
  • stack_free -frees memory of stack

Higher-order functions (using macros)

  • STACK_FOREACH - applies a function to each element of the array

Queue (using fixed-sized array)

  • queue-enqueue(value) - adds item at end of available storage
  • queue_dequeue() - removes first element from queue
  • queue_count() - returns count of elements of queue
  • queue_is_full() - returns true if queue is ful
  • queue_free() - frees memory of queue
  • queue_peek() - returns value at front of queue, don't remove from queue