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
What is the hardest programming language?
What are reserved words?
What is the size of empty structure in c?
What happens if you free a pointer twice?
A global variable when referred to in another file is declared as this a) local variable b) external variable c) constant d) pointers
Can a local variable be volatile in c?
What are the types of i/o functions?
How many data structures are there in c?
What is the meaning of c in c language?
What are qualifiers and modifiers c?
What is the advantage of c?
What is the difference between a free-standing and a hosted environment?
Why do we write return 0 in c?
What are loops c?
will u please send me the placement papers to my mail???????????????????