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

Differentiate between the = symbol and == symbol?

945


Explain what is #line used for?

813


What are called c variables?

789


int main() { Int n=20,i; For(i=0;i<=n;i--) { Printf(“-“); Return 0;

1404


What is chain pointer in c?

797


How will you divide two numbers in a MACRO?

919


Which node is more powerful and can handle local information processing or graphics processing?

1091


What is line in c preprocessor?

819


When is a void pointer used?

912


What is volatile variable in c with example?

795


What is non linear data structure in c?

792


Do character constants represent numerical values?

1088


What is %lu in c?

931


By using C language input a date into it and if it is right?

819


What is wrong with this program statement?

802