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
Is c pass by value or reference?
Explain how do you list files in a directory?
Difference between macros and inline functions? Can a function be forced as inline?
Can you please explain the difference between malloc() and calloc() function?
What are header files and explain what are its uses in c programming?
How can you allocate arrays or structures bigger than 64K?
Is there a way to have non-constant case labels (i.e. Ranges or arbitrary expressions)?
What is a list in c?
What is sizeof int in c?
What are the output(s) for the following ? #include char *f() {char *s=malloc(8); strcpy(s,"goodbye")} main() { char *f(); printf("%c",*f()='A'); }
What does malloc () calloc () realloc () free () do?
HOW TO SOLVE A NUMERICAL OF LRU IN OS ??????
how to find anagram without using string functions using only loops in c programming
what are the program that using a two dimensional array that list the odd numbers and even numbers separately in a given 10 inputs values
What is scope of variable in c?