Commit Graph

117 Commits

Author SHA1 Message Date
Ethan Fredsti 8a1a4972a5
fix: change list length in `data_structures/list/list.c` (#1265)
I changed the return value of n in List_length to reflect the number of items inside the list, so a newly initialized list will return a length of 0.  To prevent items in List_toArray from being cut off, I addeone back to n at the beginning of the List_toArray function.
2023-06-20 15:07:09 -06:00
Sahil Kandhare e278f5d74f
feat: add Dynamic Stack implementation (#1261)
* Create dynamic_stack.c

In this implementation, functions such as PUSH, POP, PEEK, show_capacity, isempty, and stack_size are coded to implement dynamic stack.

* Update dynamic_stack.c

Worked on Suggested Changes.

* Update dynamic_stack.c

Worked on suggested changes.

* Update dynamic_stack.c

* Update: Used Int type that are OS-independent

---------

Co-authored-by: David Leal <halfpacho@gmail.com>
2023-06-08 08:56:26 -06:00
Rishav Kumar 9997c8bdf0
fix: memory allocation method (#1220)
* Fix : memory allocation method

"new" is not used in C , because of that the compiler was giving compilation error.
Instead malloc was used for memory allocation.

* updating DIRECTORY.md

* Update data_structures/graphs/kruskal.c

Co-authored-by: Stepfen Shawn <m18824909883@163.com>

* updating DIRECTORY.md

---------

Co-authored-by: github-actions[bot] <github-actions@users.noreply.github.com>
Co-authored-by: Stepfen Shawn <m18824909883@163.com>
2023-03-17 12:01:44 -06:00
Sahil Kandhare f141ae4166
feat: add Circular Doubly Linked List implementation (#1038)
* Create circular_doubly_linked_list.c

* Update data_structures/linked_list/circular_doubly_linked_list.c

Co-authored-by: David Leal <halfpacho@gmail.com>

* Update circular_doubly_linked_list.c

Added brief description of library files

* Update data_structures/linked_list/circular_doubly_linked_list.c

Co-authored-by: David Leal <halfpacho@gmail.com>

* Update data_structures/linked_list/circular_doubly_linked_list.c

Co-authored-by: David Leal <halfpacho@gmail.com>

* Update circular_doubly_linked_list.c

Done the all suggested changes.

* Update data_structures/linked_list/circular_doubly_linked_list.c

Co-authored-by: David Leal <halfpacho@gmail.com>

* Update data_structures/linked_list/circular_doubly_linked_list.c

Co-authored-by: David Leal <halfpacho@gmail.com>

* Update circular_doubly_linked_list.c

* updating DIRECTORY.md

* updating DIRECTORY.md

* updating DIRECTORY.md

* Update data_structures/linked_list/circular_doubly_linked_list.c

Co-authored-by: David Leal <halfpacho@gmail.com>

* There was typo while calling delete_first_node !

* Update data_structures/linked_list/circular_doubly_linked_list.c

Co-authored-by: David Leal <halfpacho@gmail.com>

* Update data_structures/linked_list/circular_doubly_linked_list.c

Co-authored-by: David Leal <halfpacho@gmail.com>

* Update data_structures/linked_list/circular_doubly_linked_list.c

Co-authored-by: David Leal <halfpacho@gmail.com>

* Update data_structures/linked_list/circular_doubly_linked_list.c

Co-authored-by: David Leal <halfpacho@gmail.com>

* Update data_structures/linked_list/circular_doubly_linked_list.c

Co-authored-by: David Leal <halfpacho@gmail.com>

* Update data_structures/linked_list/circular_doubly_linked_list.c

Co-authored-by: David Leal <halfpacho@gmail.com>

* Update data_structures/linked_list/circular_doubly_linked_list.c

Co-authored-by: David Leal <halfpacho@gmail.com>

* Update data_structures/linked_list/circular_doubly_linked_list.c

Co-authored-by: David Leal <halfpacho@gmail.com>

* Update data_structures/linked_list/circular_doubly_linked_list.c

Co-authored-by: David Leal <halfpacho@gmail.com>

* Update data_structures/linked_list/circular_doubly_linked_list.c

Co-authored-by: David Leal <halfpacho@gmail.com>

* Update data_structures/linked_list/circular_doubly_linked_list.c

Co-authored-by: David Leal <halfpacho@gmail.com>

* Update data_structures/linked_list/circular_doubly_linked_list.c

Co-authored-by: David Leal <halfpacho@gmail.com>

* Update data_structures/linked_list/circular_doubly_linked_list.c

Co-authored-by: David Leal <halfpacho@gmail.com>

* updating DIRECTORY.md

* Suggested changes are done.

Done the suggested changes in functions 
1. delete_first_node() 
2. delete_last_node()

* updating DIRECTORY.md

* updating DIRECTORY.md

* Worked on Suggested Changes

* Suggested changes are done.

* Update circular_doubly_linked_list.c

Worked on all the suggested changes.

Co-Authored-By: David Leal <halfpacho@gmail.com>
Co-Authored-By: CascadingCascade <122662061+CascadingCascade@users.noreply.github.com>
Co-Authored-By: Taj <tjgurwara99@users.noreply.github.com>

* updating DIRECTORY.md

* updating DIRECTORY.md

* Worked on suggested changes for test cases.

Check the code's functionality [here](https://leetcode.com/playground/WcRBMWa8)

Co-Authored-By: CascadingCascade <122662061+CascadingCascade@users.noreply.github.com>

* updating DIRECTORY.md

* Update data_structures/linked_list/circular_doubly_linked_list.c

Co-authored-by: CascadingCascade <122662061+CascadingCascade@users.noreply.github.com>

* Update circular_doubly_linked_list.c

Update: Worked on suggested changes.

* Update data_structures/linked_list/circular_doubly_linked_list.c

Co-authored-by: CascadingCascade <122662061+CascadingCascade@users.noreply.github.com>

* Update data_structures/linked_list/circular_doubly_linked_list.c

Co-authored-by: CascadingCascade <122662061+CascadingCascade@users.noreply.github.com>

* Update data_structures/linked_list/circular_doubly_linked_list.c

Co-authored-by: CascadingCascade <122662061+CascadingCascade@users.noreply.github.com>

* Worked on suggested changes.

* Minor upgrade.

* updating DIRECTORY.md

---------

Co-authored-by: David Leal <halfpacho@gmail.com>
Co-authored-by: github-actions[bot] <github-actions@users.noreply.github.com>
Co-authored-by: CascadingCascade <122662061+CascadingCascade@users.noreply.github.com>
Co-authored-by: Taj <tjgurwara99@users.noreply.github.com>
2023-03-02 17:30:56 -06:00
wtz 521db035ca
docs: fix minor typos in `data_structures/avl_tree.c` (#1218) 2023-02-20 16:19:47 -06:00
ms3939 3014b7352d
feat: improve the Singly Link List implementation (#1092)
* Update singly_link_list_deletion.c

Delete function is updated to delete at any required position (not only first)

* Update singly_link_list_deletion.c

The code is changed as per the suggestions. Please lat me know if there are any changes to be done
Thank you

* Update singly_link_list_deletion.c

The code is changed as per the suggestions. Please let me know if there are any changes to be done
Thank you..

* Update singly_link_list_deletion.c

I added inserting at any input location . Please let me know if changes need to be done

* Update singly_link_list_deletion.c

* Update singly_link_list_deletion.c

I updated self tests for both insert and delete functions properly. Please let me know if any changes need to be done
Thank you

* Update singly_link_list_deletion.c

As per your suggestions I updated the code. Please let me know if any changes need to be done..

* chore: apply suggestions from code review

Co-authored-by: David Leal <halfpacho@gmail.com>
2023-01-05 17:28:08 -06:00
Anas Khan 00500d6108
chore: add display() and improve code formatting (#975)
added display to view entire stack using for loop and formatted code.
2022-11-11 13:53:44 -06:00
Enzo Veroneze 1b3a1ca91e
fix: remove double/unintended `free` (#1143)
The call to realloc() already frees the previously allocated memory if necessary.
By the man page of realloc(): "f the area pointed to was moved, a free(ptr) is done.",
and free(): "If free(ptr) has already been called before, undefined behavior occurs.".
2022-11-09 23:19:01 -06:00
Shreyas Sable 154bcdb935
feat: add a vector implementation in data structures (#977)
* added a vector implementation in data structures

* changed a comment

* made the required changes

* added tests
2022-11-08 15:18:39 -06:00
flyinghu 7e6276b730
Return success status (#957) 2022-09-30 14:20:08 +05:30
Shuangchi He 889931acc8
chore: fix various spelling typos (#945) 2022-09-27 10:58:15 -05:00
Daniel Beecham 2314a19586
feat: Rewrite the trie example (#927)
The trie example had some issues;

* It did not follow the code convention in CONTRIBUTING.md
* The createTrieNode used an inefficient zeroing method (looping over
  the entries) which also does not zero out holes in the structure (e.g.
  an alternative would be to use "*node = &(TrieNode){0}", but calloc
  does all that anyway
* It used an inefficient and clumsy printArray method
* It used strlen inside the algorithm; this new method could get rid of
  any strlen/strnlen usage (inserts/searches could be sanitized by
  snprintf)
* This version can allow for a custom mapping function, e.g. if NULL is
  a valid separator (say that you want a trie for certain binary
  packages)
* The previous version actually contained out-of-bounds array indexing;
  there were no checks for out-of-bound indexing and words in the word
  list did contain out of bounds words. It's a surprise it was working
  so well.
* This version just returns 'int' to allow for error checks (instead of
  a printf inside the algorithm), and uses double pointers for return
  values (good practice)
* The usage example contained unnecessary mallocs, switched that out for
  scanf. The example is just an example after all, in real applications
  you'd have better input sanitazion.
2022-03-19 19:04:18 -06:00
Yannick Brenning d017c3ef77
fix: update value at index and return `SUCCESS` (#932) (#933) 2022-01-15 01:34:55 +05:30
Idan BananI 0ceb3b340e
Update dijkstra.c (#928)
in this way valgrind checks will pass and result will stay the same (functions as a static variable)
2022-01-11 23:50:32 +05:30
Lorenzo Battistela 9bbec45d13
feat: Moving queue file to it's directory and creating include file for it (#874)
* Putting queue in correct dir and creating include file for it

* Update data_structures/queue/include.h

missing one function, added

Co-authored-by: David Leal <halfpacho@gmail.com>

Co-authored-by: David Leal <halfpacho@gmail.com>
2021-10-15 11:28:04 -05:00
Randy Kwalar 1b30b89083
feat: Added a program that prints words in alphabetical order using binary tree data structure (#841)
* frequencies of words started

* A program to Print words contained in a file in alphabetical order

* Apply suggestions from code review

Co-authored-by: David Leal <halfpacho@gmail.com>

* appropriate comments added as suggested from code review

* comments cleaned up

* updating DIRECTORY.md

* Apply suggestions from code review

Co-authored-by: David Leal <halfpacho@gmail.com>

* commenting re-worded

* Add link to algorithm

* Update data_structures/binary_trees/words_alphabetical.c

Co-authored-by: David Leal <halfpacho@gmail.com>

* Update data_structures/binary_trees/words_alphabetical.c

Co-authored-by: David Leal <halfpacho@gmail.com>

* main function moved to the bottom and function prototypes deleted

* uint64_t data type used for non negative values

* uint8_t used

* all int types fixed

* detailed explanation of algorithm added

* Update data_structures/binary_trees/words_alphabetical.c

Co-authored-by: David Leal <halfpacho@gmail.com>

* Update data_structures/binary_trees/words_alphabetical.c

Co-authored-by: David Leal <halfpacho@gmail.com>

* Update data_structures/binary_trees/words_alphabetical.c

Co-authored-by: David Leal <halfpacho@gmail.com>

* tests and documentation added

* Update data_structures/binary_trees/words_alphabetical.c

Co-authored-by: David Leal <halfpacho@gmail.com>

* Update data_structures/binary_trees/words_alphabetical.c

Co-authored-by: David Leal <halfpacho@gmail.com>

* Update data_structures/binary_trees/words_alphabetical.c

Co-authored-by: David Leal <halfpacho@gmail.com>

* Update data_structures/binary_trees/words_alphabetical.c

Co-authored-by: David Leal <halfpacho@gmail.com>

* Update data_structures/binary_trees/words_alphabetical.c

Co-authored-by: David Leal <halfpacho@gmail.com>

* Update data_structures/binary_trees/words_alphabetical.c

Co-authored-by: David Leal <halfpacho@gmail.com>

* Update data_structures/binary_trees/words_alphabetical.c

Co-authored-by: David Leal <halfpacho@gmail.com>

* Update data_structures/binary_trees/words_alphabetical.c

Co-authored-by: David Leal <halfpacho@gmail.com>

* Update data_structures/binary_trees/words_alphabetical.c

Co-authored-by: David Leal <halfpacho@gmail.com>

* Update data_structures/binary_trees/words_alphabetical.c

Co-authored-by: David Leal <halfpacho@gmail.com>

* Update data_structures/binary_trees/words_alphabetical.c

Co-authored-by: David Leal <halfpacho@gmail.com>

* Update data_structures/binary_trees/words_alphabetical.c

Co-authored-by: David Leal <halfpacho@gmail.com>

* Update data_structures/binary_trees/words_alphabetical.c

Co-authored-by: David Leal <halfpacho@gmail.com>

* documentation added

* Update data_structures/binary_trees/words_alphabetical.c

Co-authored-by: David Leal <halfpacho@gmail.com>

* Update data_structures/binary_trees/words_alphabetical.c

Co-authored-by: David Leal <halfpacho@gmail.com>

* Update data_structures/binary_trees/words_alphabetical.c

Co-authored-by: David Leal <halfpacho@gmail.com>

* Update data_structures/binary_trees/words_alphabetical.c

Co-authored-by: David Leal <halfpacho@gmail.com>

* Update data_structures/binary_trees/words_alphabetical.c

Co-authored-by: David Leal <halfpacho@gmail.com>

* Update data_structures/binary_trees/words_alphabetical.c

Co-authored-by: David Leal <halfpacho@gmail.com>

* Update data_structures/binary_trees/words_alphabetical.c

Co-authored-by: David Leal <halfpacho@gmail.com>

* Update data_structures/binary_trees/words_alphabetical.c

Co-authored-by: David Leal <halfpacho@gmail.com>

* Update data_structures/binary_trees/words_alphabetical.c

Co-authored-by: David Leal <halfpacho@gmail.com>

* Update data_structures/binary_trees/words_alphabetical.c

Co-authored-by: David Leal <halfpacho@gmail.com>

* Update data_structures/binary_trees/words_alphabetical.c

Co-authored-by: David Leal <halfpacho@gmail.com>

* Update data_structures/binary_trees/words_alphabetical.c

Co-authored-by: David Leal <halfpacho@gmail.com>

* Apply suggestions from code review

Co-authored-by: David Leal <halfpacho@gmail.com>

* documentation added

* Apply suggestions from code review

Co-authored-by: David Leal <halfpacho@gmail.com>

* Add documentation

Co-authored-by: David Leal <halfpacho@gmail.com>
Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2021-07-30 16:17:09 +05:30
Mainak Debnath 4ac1c65007
fix: Added `limits.h` in `data_structures/heap/max_heap.c` (#812)
* fix: added limits.h header

* fix: added limits.h header in max_heap.c

* update: adding better documentation

* update: added documentation for header files

* update: changed comment for header files

Co-authored-by: David Leal <halfpacho@gmail.com>
2021-03-16 12:07:52 -06:00
Ayaan Khan 5eee22a750
Merge pull request #768 from Suraj-Patro/patch-28
fix: Improved source code formatting at data_structures/linked_list/stack_using_linked_lists.c
2021-02-11 10:15:51 +05:30
Ravi Shankar Reddy B 14d29d559a
fixed: 761, 762. Fixed mis-spelled header file CArray.h to carray.h (#783)
Co-authored-by: Ravi Shankar Reddy Bommana <ravishankarreddy.bommana@citrix.com>
2021-01-24 23:04:33 -06:00
谭九鼎 88fc8bb03d
fix: md style (#779) 2021-01-01 20:12:34 -06:00
meenal2000 aef9d8d53f
fix: file names modified for better readability (#770)
* file names modified

* files name modified

* file names modified

* updating DIRECTORY.md

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2020-11-03 18:46:26 -06:00
Suraj Patro 752cde71ef
Update stack_using_linked_lists.c 2020-10-31 00:13:40 +05:30
Gabriel Mota Bromonschenkel Lima 778f317e82
Rename redblacktree.c to red_black_tree.c (#684)
* Rename redblacktree.c to red_black_tree.c

* updating DIRECTORY.md

* add renaming avl.c and ascendingpriorityqueue.c

* updating DIRECTORY.md

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2020-10-20 12:51:47 -04:00
Gabriel Mota Bromonschenkel Lima 74e81de85a
Doubly linked list, simple code. (#673)
* Doubly linked list, simple code.

#633

* organizing code a bit more

* add link in DIRECTORY.md and more comments/cleaning.

* remove global variables and redundancy.

* add Wikipedia reference

* add documentation comments in all functions/headers

* add update in file brief

Co-authored-by: Krishna Vedala <7001608+kvedala@users.noreply.github.com>

* remove part of file @details

Co-authored-by: Krishna Vedala <7001608+kvedala@users.noreply.github.com>
2020-10-20 12:50:48 -04:00
Lza-etc adcbc39e3c
Rename CircularLinkedList.C to circular_linked_list.c (#679) 2020-10-19 18:31:01 -04:00
Shezza221b d3bb124b90
docs: Minor documentation improvements (data_structures/queue.c) (#616) 2020-10-01 12:19:55 -05:00
devraj4522 6f385ed4a4
Update queue.c (#622) 2020-10-01 10:28:19 -04:00
Shezza221b af6de4b7d4
Update stack.c (#617) 2020-10-01 09:34:03 -04:00
Lakhan Nad e75d0e75d7
Feature: Added segment_trees Closes #561 (#595)
* Feature: Added segment_trees Closes #561

* doc: documentation improved and explanations added

* updating DIRECTORY.md

* doc: changes in documentation

* doc: suggested doc changes and int types changed

* update: doc change for main function

Co-authored-by: David Leal <halfpacho@gmail.com>

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
Co-authored-by: David Leal <halfpacho@gmail.com>
2020-09-09 12:50:21 -04:00
Krishna Vedala 296f3d00d0
[bug+docs] add docs + fix error in getMax (#579)
* add docs + fix error in getMax

* fix clang-tidy alerts and errors

* rearrange comments

* allow subfolders in data_structure

* set pointer to NULL after purge
2020-07-22 08:37:28 -04:00
Krishna Vedala 6470f0318b
fixed documentations 2020-06-28 15:18:52 -04:00
github-actions 6f98288110 formatting source-code for 5bba04b671 2020-06-28 15:25:37 +00:00
github-actions 5347e6f87d formatting source-code for b1d92cbdda 2020-06-20 11:28:26 +00:00
Krishna Vedala 4d01cb2e88
Merge commit '7c815b86b20ddc07ee1f33753f370baf63cc48aa' into documentation/fixes
Signed-off-by: Krishna Vedala <7001608+kvedala@users.noreply.github.com>
2020-06-13 14:12:48 -04:00
Amit 590173ec81 added ref 2020-06-11 20:17:13 +05:30
Amit cf4e320726 added details 2020-06-11 20:13:45 +05:30
Amit 81d568da82 changed brief 2020-06-11 20:04:08 +05:30
Amit 522183b96c changed filename 2020-06-11 19:50:50 +05:30
Amit e77581f788 filename and functionname updated 2020-06-11 19:47:53 +05:30
Amit e63c806f25 updated documentation and format 2020-06-11 19:35:59 +05:30
Amit 93e1bfc1f9 added threaded binary tree 2020-06-11 14:23:07 +05:30
github-actions 466ccaa407 formatting filenames 909e15d8be 2020-05-30 18:26:19 +00:00
Krishna Vedala 909e15d8be manually rename folder and files to lower-case 2020-05-30 14:25:30 -04:00
github-actions 0779a2b70d formatting source-code for b388e4a309 2020-05-29 20:23:24 +00:00
Sombit Bose 1c07d61ce3
Merge pull request #538 from shubhamsah/master
Added Priority Queue, Queue (link list) and Merge Sort
2020-05-28 15:12:18 +05:30
Shubham Sah b86a4747ca
Create queue_linked_list.c
Implementation of Queue using Linked List.
2020-05-28 12:26:56 +05:30
Shubham Sah 2a4fd0b735
Update and rename ascendingPriorityQueue.c to ascendingpriorityqueue.c 2020-05-28 11:29:24 +05:30
Shubham Sah a652d51791
Update AscendingPriorityQueue.c
Added the output of the file
2020-05-26 21:06:32 +05:30
Sombit Bose 23df4b58d8
Update File
A Demo Sample Test case added
2020-05-26 20:58:51 +05:30
Shubham Sah 9ed17fc3c9
Create Ascending Priority Queue
Code to implement Ascending Priority Queue
2020-05-23 21:29:54 +05:30