pgm to find middle element of linklist(in efficent manner)

Answer Posted / ashwini

struct node
{
int data;
struct node *ptr;
};


struct node mid_element(struct node* head)//since we pass addr
{
int count=0,n_count,i=0;
struct node* temp,*mid;
temp=mid=head;
while(temp -> ptr != NULL)
{
count++;
temp = temp->otr;
}
count++;

if(count % 2)
{
n_count = (count/2)+1;
for(i=0 ; i<n_count ; i++)
mid = mid -> ptr;
}

return mid;
}

Is This Answer Correct ?    2 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the hardest programming language?

673


What are reserved words?

661


What is the size of empty structure in c?

596


What happens if you free a pointer twice?

613


A global variable when referred to in another file is declared as this a) local variable b) external variable c) constant d) pointers

652






Can a local variable be volatile in c?

584


What are the types of i/o functions?

685


How many data structures are there in c?

620


What is the meaning of c in c language?

599


What are qualifiers and modifiers c?

552


What is the advantage of c?

613


What is the difference between a free-standing and a hosted environment?

644


Why do we write return 0 in c?

557


What are loops c?

618


will u please send me the placement papers to my mail???????????????????

1367