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

Is c pass by value or reference?

1027


Explain how do you list files in a directory?

1059


Difference between macros and inline functions? Can a function be forced as inline?

1249


Can you please explain the difference between malloc() and calloc() function?

1104


What are header files and explain what are its uses in c programming?

1106


How can you allocate arrays or structures bigger than 64K?

1119


Is there a way to have non-constant case labels (i.e. Ranges or arbitrary expressions)?

1052


What is a list in c?

1018


What is sizeof int in c?

1045


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'); }

1165


What does malloc () calloc () realloc () free () do?

1050


HOW TO SOLVE A NUMERICAL OF LRU IN OS ??????

2676


how to find anagram without using string functions using only loops in c programming

3172


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

1681


What is scope of variable in c?

1026