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

Can a local variable be volatile in c?

665


Describe explain how arrays can be passed to a user defined function

708


What is function prototype in c language?

692


Write a code to determine the total number of stops an elevator would take to serve N number of people.

837


What is optimization in c?

652






how to find binary of number?

3658


Is there a way to jump out of a function or functions?

747


Tell me what is null pointer in c?

687


WRITE A CODE IN C TO SEARCH A FILE FROM NOTEPAD FILE.

2119


How the c program is executed?

736


What is getch () for?

786


Explain what’s a signal? Explain what do I use signals for?

686


How can I write data files which can be read on other machines with different word size, byte order, or floating point formats?

701


What is the difference between text and binary i/o?

665


What is volatile keyword in c?

668