I’m trying to add elements enter by the user in a BST.For this I’ve used 2 functions, one is used to create the function and other is just used to insert element to the tree. One is a pre-order function that is used to check if insertion is done or not Initially I tried to ..

#### Category : data-structures

I’m dealing with data structures in C++ for practicing purposes and I’m currently playing a bit with graphs. I’d like to connect my program to a graph database just to check out how these databases work. How can this be done with C++? What database would be the optimal solution? I was about to use ..

I have a directed graph. Initially, all nodes are assumed to be unvisited and flag is -1 in vector<int>flag. Now we start from a source node & push into stack<int>s and make flag[source]=0 . Now I do DFS traversal & push nodes if(flag[node]==-1)& make flag[node]=0. if all the DFS directed links are visited I pop ..

I am fairly new to dynamic programming, i have seen people, memoize in javascript using objects. But i would like to know what will be the most efficient way to memoize in c++. Which data structure should i use, is map good? orr is there something better, please let me know. Source: Windows Que..

PROBLEM STATEMENT CONSTRAINTS GIVEN Find different number of strings obtained. Source: Windows Que..

This is my code, it shows me different output when compiling it with GCC and Clang. Clang Output is what expected, but why GCC behaves that way? #include <stdio.h> #include <stdlib.h> typedef struct node NODE; struct node { int val; NODE* next; }; NODE* mknode(int val) { NODE* tmp = (NODE* ) malloc(sizeof(NODE)); tmp->next = ..

kindly check the code below for implementing stack using linked list, I m facing issues with the do-while part where switch case is used. The compiler is not taking any input for those two variables (1. int option and 2. Char c ), if I give a default value for the two the code executes ..

I was trying to solve this problem in leetcode. problem: heap problem this is my code: class Solution { public: vector<string> findRelativeRanks(vector<int>& score) { priority_queue<pair<int,int>,vector<pair<int,int>>>mxheap; for(int i=0; i<score.size(); i++){ mxheap.push({score[i],i}); } vector<string>ans(score.size()); int place = 1; while(!mxheap.empty()){ switch(place){ case 1: ans[mxheap.top().second] = "Gold Medal"; mxheap.pop(); break; case 2: ans[mxheap.top().second] = "Silver Medal"; mxheap.pop(); break; case ..

This problem is about adding two sparse matrix. At first i created two sparse matrix s1,s2 (taking the elements value manually) then adding them in sum. If i run it in code blocks i got false ans. but if i debug and run it…then the ans i got is perfect. This thing is hapenning again ..

Problem -> You are given a positive number N, at a time you can either increase or decrease number by 1. Find minimum number of such moves to convert given number into lucky number. Lucky Number -> If all digits of the number are even then it is a lucky number. example-> N=82, min-steps = ..

## Recent Comments