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
Can you please explain the difference between strcpy() and memcpy() function?
How can I run c program?
What is array of structure in c programming?
Write a Program to find whether the given number or string is palindrome.
Explain the difference between malloc() and calloc() function?
How can I recover the file name given an open stream or file descriptor?
What are the keywords in c?
Write a C program to count the number of email on text
What are the different types of endless loops?
How can I find out how much free space is available on disk?
What is a 'null pointer assignment' error? Explain what are bus errors, memory faults, and core dumps?
What is atoi and atof in c?
What is file in c language?
What is bubble sort in c?
Explain about block scope in c?