Tagged Questions
3
votes
6answers
461 views
What is really happening in this code?
I have a code which includes a recursive function. I have wasted a lot of time on recursion but I still couldn't get it really:
#include<stdio.h>
void count(int);
int main()
{
int x=10,z;
...
35
votes
6answers
19k views
self referential struct definition?
I haven't been writing C for very long, and so I'm not sure about how I should go about doing these sorts of recursive things... I would like each cell to contain another cell, but I get an error ...
9
votes
3answers
13k views
Linked list recursive reverse
I was looking at the code below from stanford library:
void recursiveReverse(struct node** head_ref)
{
struct node* first;
struct node* rest;
/* empty list */
if (*head_ref == NULL)
...
41
votes
7answers
9k views
What exactly is a reentrant function?
Most of the times, the definition of reentrance is quoted from Wikipedia:
A computer program or routine is
described as reentrant if it can be
safely called again before its
previous ...
3
votes
2answers
3k views
How to recursively list directories in C on LINUX
I know that there are questions similar to this, but a lot of them are very open and don't help me too much...
I need to recursively list all directories and files in C programming. I have looked ...
-3
votes
3answers
697 views
What is recursion really and explain the output of this program? [closed]
I really can't understand this code. When a function calls itself what really happens? It is related to the concept of stack, I know, but still I can't solve these questions.
#include<stdio.h>
...
6
votes
3answers
6k views
How Recursion works in C
I am new to C and I'm reading about recursion, but I am totally confused.
The main part where I'm getting confused is how things get unwind when the exit condition is reached. I would like to know ...
2
votes
2answers
2k views
Tail recursion in C
I was trying to write recursion function,to find factorial of a number.
int factorial(int input,int *answer)
{
if ( input ==0 )
{
return ...
1
vote
5answers
540 views
Converting an iterative function to recursive
I know people usually ask this question the other way round, but I have the following problem:
I have this iterative function which counts all the nodes in a circular doubly link list containing the ...
0
votes
3answers
208 views
Recursion in C. Making a non-recursive function a recursive one
gcd should be a recursive function. It should return void. It should take two positive integers and place the GCD in the third parameter.
Here is my coded gcd function. However, I realized that ...
0
votes
6answers
1k views
Recursion in C, understand recursion example
i am having trouble understanding this example. I cant figure out what actually happens after a certain point.
Here is the code, the result is supposed to be 4.
I can see that it calls itself ...
0
votes
4answers
93 views
What is the difference between the two locations?
I have a recursive program. When the printf is used in the function, it outputs 123 and when used outside, it outputs 0123 .
#include <stdio.h>
fact(int);
int main()
{
int x=3;
...
-3
votes
4answers
424 views
How write a recursive print program
Gurus,
I want to know how to write a recursive function that prints
1
12
123
1234
...
......
For eg: display(4) should print
1
12
123
1234
Code
#include <stdio.h>
void print(int n)
{
...
30
votes
6answers
2k views
Determining the complexities given codes
Given a snipplet of code, how will you determine the complexities in general. I find myself getting very confused with Big O questions. For example, a very simple question:
for (int i = 0; i < n; ...
11
votes
5answers
3k views
Traverse tree without recursion and stack in C
How to traverse each node of a tree efficiently without recursion in C (no C++)?
Suppose I have the following node structure of that tree:
struct Node
{
struct Node* next; /* sibling node ...