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
What is malloc return c?
Is c procedural or object oriented?
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.
Differentiate Source Codes from Object Codes
Write a program to use switch statement.
What is volatile variable how do you declare it?
What is bubble sort technique in c?
What is d scanf?
write a c program for swapping two strings using pointer
Give a one-line C expression to test whether a number is a power of 2. [No loops allowed - it's a simple test.]
What is page thrashing?
Where is c used?
What is actual argument?
Explain continue keyword in c
What is a substring in c?