pgm to find middle element of linklist(in efficent manner)

Answer Posted / 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 ?    4 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is malloc return c?

603


Is c procedural or object oriented?

585


Write a program to replace n bits from the position p of the bit representation of an inputted character x with the one's complement. Method invertBit takes 3 parameters x as input character, p as position and n as the number of positions from p. Replace n bits from pth position in 8 bit character x. Then return the characters by inverting the bits.

3694


Differentiate Source Codes from Object Codes

828


Write a program to use switch statement.

662






What is volatile variable how do you declare it?

570


What is bubble sort technique in c?

594


What is d scanf?

599


write a c program for swapping two strings using pointer

2098


Give a one-line C expression to test whether a number is a power of 2. [No loops allowed - it's a simple test.]

635


What is page thrashing?

655


Where is c used?

656


What is actual argument?

595


Explain continue keyword in c

590


What is a substring in c?

591