Skip to content

Commit 9997c8b

Browse files
i-m-afkgithub-actions[bot]StepfenShawn
authored
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 <[email protected]> * updating DIRECTORY.md --------- Co-authored-by: github-actions[bot] <[email protected]> Co-authored-by: Stepfen Shawn <[email protected]>
1 parent acbaf4a commit 9997c8b

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

data_structures/graphs/kruskal.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ struct Graph
2727
// Creates a graph with V vertices and E edges
2828
struct Graph *createGraph(int V, int E)
2929
{
30-
struct Graph *graph = new Graph();
30+
struct Graph* graph = (struct Graph*)(malloc(sizeof(struct Graph)));
3131
graph->V = V;
3232
graph->E = E;
3333

34-
graph->edge = new Edge[E];
34+
graph->edge = (struct Edge*)malloc(sizeof(struct Edge) * E);
3535

3636
return graph;
3737
}

leetcode/DIRECTORY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
| 24 | [Swap Nodes in Pairs](https://leetcode.com/problems/swap-nodes-in-pairs) | [C](./src/24.c) | Medium |
2828
| 26 | [Remove Duplicates from Sorted Array](https://leetcode.com/problems/remove-duplicates-from-sorted-array) | [C](./src/26.c) | Easy |
2929
| 27 | [Remove Element](https://leetcode.com/problems/remove-element) | [C](./src/27.c) | Easy |
30-
| 28 | [Find the Index of the First Occurrence in a String](https://leetcode.com/problems/find-the-index-of-the-first-occurrence-in-a-string) | [C](./src/28.c) | Medium |
30+
| 28 | [Find the Index of the First Occurrence in a String](https://leetcode.com/problems/find-the-index-of-the-first-occurrence-in-a-string) | [C](./src/28.c) | Easy |
3131
| 29 | [Divide Two Integers](https://leetcode.com/problems/divide-two-integers) | [C](./src/29.c) | Medium |
3232
| 32 | [Longest Valid Parentheses](https://leetcode.com/problems/longest-valid-parentheses) | [C](./src/32.c) | Hard |
3333
| 35 | [Search Insert Position](https://leetcode.com/problems/search-insert-position) | [C](./src/35.c) | Easy |

0 commit comments

Comments
 (0)