program to find middle element of linklist?



program to find middle element of linklist?..

Answer / abdur rab

struct node {
int data;
struct node* next;
};

int mid_element ( struct node* _node )
{
struct node* cur_ptr;
struct node* cur_next_ptr;

if ( NULL == _node ) return ( -1 );
else {
cur_ptr = _node;
cur_next_ptr = _node;
while ( ( NULL != cur_ptr -> next )
&& ( NULL != cur_next_ptr -
> next )
&& ( NULL != cur_next_ptr -
> next -> next ) )
{
cur_ptr = cur_ptr -> next;
cur_next_ptr = cur_next_ptr ->
next -> next;
}
}

return ( cur_ptr -> data );
}

Is This Answer Correct ?    8 Yes 2 No

Post New Answer

More C Interview Questions

What are called c variables?

0 Answers  


What is an auto variable in c?

0 Answers  


Is struct oop?

0 Answers  


Who had beaten up hooligan "CHAKULI" in his early college days?

1 Answers  


What is the difference between scanf and fscanf?

0 Answers  






How can I run c program?

0 Answers  


To print the pattern 1 2 3 4 5 10 17 18 19 6 15 24 25 20 7 14 23 22 21 8 13 12 11 10 9

0 Answers   HCL,


Program to find the sum of digits of a given number until the sum becomes a single digit. (e.g. 12345=>1+2+3+4+5=15=>1+5=6)

0 Answers   InterGraph,


difference between my-strcpy and strcpy ?

3 Answers   Geometric Software, IIM, Infosys,


main() { printf("hello%d",print("QUARK test?")); }

5 Answers  


how 2 compile & execute c program with out using editor?

2 Answers   HP,


can we print any string without using terminator?

2 Answers   Infosys, TCS,


Categories