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

How can you draw circles in C?

1198


Was 2000 a leap year?

1093


Write a factorial program using C.

1123


What is the use of pointers in C?

1137


What are the types of data types and explain?

1138


Is fortran still used in 2018?

1099


shorting algorithmS

2315


write a program to print data of 5 five students with structures?

2093


show how link list can be used to repersent the following polynomial i) 5x+2

2403


How can you call a function, given its name as a string?

1210


When should structures be passed by values or by references?

1087


Why we write conio h in c?

1082


What is the advantage of a random access file?

1259


What is main return c?

1050


Explain what are the different data types in c?

1271