program to find middle element of linklist?

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 ?    8 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How to create struct variables?

810


Can you define which header file to include at compile time?

797


Write a program to swap two numbers without using the third variable?

808


In the DOS enveronment, normal RAM that resides beyond the 1mb mark. a) expanded memory b) swapped memory c) Extended memory d) none

979


the real constant in c can be expressed in which of the following forms a) fractional form only b) exponential form only c) ascii form only d) both a and b

2362


Can 'this' pointer by used in the constructor?

819


What are local static variables? How can you use them?

848


There is a practice in coding to keep some code blocks in comment symbols than delete it when debugging. How this affect when debugging?

1055


What is c programming structure?

827


What is the scope of global variable in c?

755


What is meant by gets in c?

809


What is the difference between the = symbol and == symbol?

822


#define PRINT(int) printf("int = %d ",int) main() {< BR> intx,y,z; x=03;y=02;z=01; PRINT(x^x); z<<=3;PRINT(x); y>>=3;PRINT(y); }

956


What is the correct declaration of main?

907


I just typed in this program, and it is acting strangely. Can you see anything wrong with it?

762