Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

Can you please explain the difference between strcpy() and memcpy() function?

1019


How can I run c program?

1132


What is array of structure in c programming?

1242


Write a Program to find whether the given number or string is palindrome.

1231


Explain the difference between malloc() and calloc() function?

989


How can I recover the file name given an open stream or file descriptor?

1033


What are the keywords in c?

1080


Write a C program to count the number of email on text

1857


What are the different types of endless loops?

1029


How can I find out how much free space is available on disk?

1016


What is a 'null pointer assignment' error? Explain what are bus errors, memory faults, and core dumps?

1171


What is atoi and atof in c?

1031


What is file in c language?

966


What is bubble sort in c?

1005


Explain about block scope in c?

1034