Skip to main content
The 2024 Developer Survey results are live! See the results

All Questions

Tagged with
-1 votes
2 answers
84 views

I want my 2nd if-statement to do a recursion-type loop but it is not returning anything and defaulting to false, what am i doing wrong?

bool isPalindrome(string some_string) { if (some_string.length() == 0 || some_string.length() == 1) { return true; } if (some_string[0] == some_string[some_string.length() - 1]) { ...
Huzaifa Siddiqui's user avatar
2 votes
2 answers
99 views

Circular linked list, destructor delete order causing seg-fault

Overview I have a simple circularly linked list I was making for demonstration purposes (I know I should be using smart pointers, but this is a pedagogical exercise for memory and data structures). ...
Amiel's user avatar
  • 21
4 votes
1 answer
138 views

In C++, how can we write a recursive function that returns a range?

In C++ we face 2 problems when writing a recursive function that returns a range the base case type is different from the recursive case type ranges often involve lambdas, so the return type is auto, ...
V. Semeria's user avatar
  • 3,226
0 votes
5 answers
155 views

why this code's return value doesn't cover all control path?

TreeNode* searchBST(TreeNode* root, int val) { if(root==nullptr)return nullptr; if(root->val==val)return root; if(root->val<val)return searchBST(root->right,val); ...
user25359626's user avatar
2 votes
0 answers
48 views

Coin Change Recursive, memoization gone wrong

I'm trying to understand why first one fails and second works, all I'm doing is passing along coinTrack, call it redundant but why does it not work? It works without memoization, but on using ...
user2643191's user avatar
1 vote
1 answer
95 views

Change recursive into iterative function

I got a recursive function for exporting information and I want to transform it into an iterative one for efficiency reasons (toy problem below). However, as there are statements in the recursive ...
RocketSearcher's user avatar
-2 votes
1 answer
115 views

Coin Change: for loop analysis

I am trying to comprehend the problem which has different wording but I figured it is similar to coin change problem Question: Two friends are playing a game with a book numbered from 1 to 9. The game ...
Lishant's user avatar
  • 43
-2 votes
1 answer
85 views

What is the use of creating a copy of the input in a recursive call?

This is a code to generate all the substrings in of a given vector class Solution { public: void sub(vector<int> &ip, vector<int> &op, vector<vector<int>> &ans) ...
hash's user avatar
  • 1
0 votes
0 answers
41 views

Calculating natural logarithm without predefined functions in C++ [duplicate]

I'm doing an assignment problem that requires me to write a ln (natural logarithm) function, using the divide and conquer / divide et impera technique that takes a float x as its parameter and finds ...
Andrei Trifan's user avatar
0 votes
0 answers
40 views

Issues with passing a pointer via reference in Cpp

void insertNodeInternal(int v, Node* &selectedNode){ if (selectedNode == nullptr) { selectedNode = new Node(v); } else if (v <= selectedNode->GetValue())...
petr chyla's user avatar
1 vote
0 answers
92 views

Different specializations of class template invokes static member function of each other recursively

The function Dictate<T> is used to collect type informations about T。If there are any orhter types associated with the type T their information is collected also. The class template type is ...
王雨泽's user avatar
0 votes
1 answer
79 views

What are the trades off for implementing recursion as a problem solving tool? [closed]

I implemented a simple recursive average calculator in C++, where the 'Student' must enter their grades and the function returns their Average. But I'm wondering if I have any advantage to using ...
Kayque Amado's user avatar
1 vote
1 answer
45 views

How to define variable template and its specialized version in a `.h` file?

I've run into some tricky issues with recursive variable template. I define variable template with non-type template parameters and its specialization in mymath.h to implement the factorial. Any non-...
Xshell's user avatar
  • 55
-1 votes
1 answer
85 views

A strange over-append by the function

In this section of homework, we are asked to write a function ctx_append (abbreviation of context append, I guess), which should operate like this: Before: ctx_k: { "a", "b", &...
OW1TY2's user avatar
  • 9
-1 votes
1 answer
59 views

Recursion calculating Legendre Polynom not working (segmentation fault) [C++]

I made a function in C++ that calculates the N-th Legendre polynomial and its derivative based on recursive formulas. It returns either zeros, bogus numbers or the "segmentation fault" error....
Josip Gregorić's user avatar

15 30 50 per page
1
2 3 4 5
258