search
Log In
1 vote
111 views

Why here implementation A is wrong.I feel it is correct.

in Programming 111 views
1
head is a pointer of type node, which contains the address of the first node. head will be passed as parameter to this function insert, so to hold a pointer we need a double pointer variable.

for example

int i;

int *a = &i;

int **b =&a;

so, technically code 2 is correct but not code 1.
0
Thank you
0
@manu

Suppose

Linked list nodes are like {Data , Next node ptr}

Address of head = 4000.

Address of head_ref = 5000

Head_ref {4000}|

Head{1000} -> {1,2000} -> {2,3000} -> {3, NULL}

 

NewNode{x, NULL}  (suppose address of NewNode 6000)

After implementation first code

NewNode{x, 1000}

Head{6000}

I here looking everything is fine , how implementation is wrong. Please describe .I am not getting
0
@manu sir,

head_ref is pointer to head pointer thats why ** is correct

and also head is pointer to LL so simply * is also correct. I think everything looks fine.!
0
Manu sir,

 As you said, to hold a pointer variable we a need double pointer variable.. then what type of variable do we need to hold the address of a pointer type variable?
0
I feel code 1 is also correct.
0
I am sorry! I think code 1 is also correct, as it's pass by value.

If function insert is called as insert(1000,5); then head will contain the value 1000, we are not storing the address of head.

Please log in or register to answer this question.

Related questions

1 vote
2 answers
1
84 views
I am getting answer as 9 T(3,1) -> T(2,3) - T(1,7) I got T(1,7) value as 9 .
asked Nov 5, 2017 in Programming Niharika 1 84 views
0 votes
0 answers
2
69 views
Here first if condition is assigning value of 1 to every array element and doing minus right?? Then every array value will be zero right?
asked Nov 4, 2017 in Programming Niharika 1 69 views
0 votes
0 answers
3
93 views
Let us say we assume last production rule to be $A \rightarrow \epsilon$ The language generated by the given grammar will be something like $L = \{c, bcb, b^2cb^2, b^3cb^3, \dots\}$. Is this a regular language. Is it possible to construct DFA for L?
asked Dec 9, 2018 in Theory of Computation !KARAN 93 views
0 votes
0 answers
4
102 views
For $\text{A, B} \subseteq \Sigma^*,$ define $A/B = \{x \in \Sigma^* | \exists y \in B , xy \in A \}$ If L is a CFL and R is regular, then L/R is Regular CFL but not regular Recursive but not CFL None of the above To solve this problem I am trying ... which we know that are not regular but they are CFL. Hence, $L/R$ is CFL but not Regular. Please advise me that am I thinking in correct way or not?
asked Dec 8, 2018 in Theory of Computation !KARAN 102 views
...