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 static and dynamic modeling.

626


When c language was developed?

644


what do the 'c' and 'v' in argc and argv stand for?

649


How can a program be made to print the name of a source file where an error occurs?

735


Explain what are the different data types in c?

762






What is sizeof c?

613


What are terms in math?

596


Why shouldn’t I start variable names with underscores?

628


What is a void pointer? When is a void pointer used?

630


What is .obj file in c?

650


How do shell structures work?

574


Why c is called a mid level programming language?

607


What is include directive in c?

649


Differentiate call by value and call by reference?

571


What is an example of structure?

591