Find the middle node in the linked list??
(Note:Do not use for loop, count and count/2)

Answers were Sorted based on User's Feedback



Find the middle node in the linked list?? (Note:Do not use for loop, count and count/2)..

Answer / kstarmind

Keep two pointers,
1. fast pointer moves two nodes at a time
2. slow pointer moves one node at a time

keep moving both the pointers, once the fast pointer reaches
the end node, your slow pointer would be at middle of the list.

Is This Answer Correct ?    47 Yes 5 No

Find the middle node in the linked list?? (Note:Do not use for loop, count and count/2)..

Answer / om

just use recursion .....it's simple......

Is This Answer Correct ?    4 Yes 3 No

Find the middle node in the linked list?? (Note:Do not use for loop, count and count/2)..

Answer / santhoshr

It wont work exactly if the no of nodes is not given!!! So
better answer is having two pointers from first itslf.
And like this , another question is there,
to find the pth node from last!! That too haas the same logic!!!

Is This Answer Correct ?    2 Yes 1 No

Find the middle node in the linked list?? (Note:Do not use for loop, count and count/2)..

Answer / kar..

move the front pointer and rear pointer at equal
intervel,these both pointe will meet at one node is middle...

Is This Answer Correct ?    2 Yes 3 No

Find the middle node in the linked list?? (Note:Do not use for loop, count and count/2)..

Answer / dhr

it also works

Is This Answer Correct ?    1 Yes 3 No

Find the middle node in the linked list?? (Note:Do not use for loop, count and count/2)..

Answer / vadivel

U mean without any looping statements r just for loop?????
It can be done in a single traversal using Hare n turtle
method as said above using a for or while loop.....
Without using looping statements d list can't be traversed..
Plz make the question clear.....

Is This Answer Correct ?    3 Yes 10 No

Post New Answer

More C Interview Questions

if a is an integer variable, a=5/2; will return a value a) 2.5 b) 3 c) 2 d) 0

0 Answers  


How do you define CONSTANT in C?

0 Answers   ADP,


Topics: Structures, Arrays, Searching and Sorting Assume there is a small mobile computer device including a hard disk and a slot for a memory card. The device shall be used to backup photos e.g. during holiday. Every time a memory card is connected all photos of the card are copied into a new folder automatically. And your task is to develop some basic controlling software to show, add, remove, search and sort the directories of photos. Step by Step Implementation 1.Define two symbolic constants, one to hold the total volume of the disk (e.g. VOLUME) and another one to hold the number of entries the files system of the device can handle (MAXFOLD). 2.Define a new structure data type named DATE to store a date consisting of year, month and day as unsigned values. 3.Define an other structure data type FOLDER to store the information of one folder of photos: ◦A title as character array of appropriate length ◦The location (event) the photos are taken as character array of appropriate length ◦The date of the day the photos are copied to the disk using the just defined data type DATE ◦The number of photos as natural number ◦And the size of the folder in MB as floating point value 4.Define the following global variables and initialise them: ◦disk as an array with MAXFOLD elements of data type FOLDER ◦folders as natural value to count the number of folders currently stored at the disk (valid elements in the array) TEST: Now you should be able to compile the code the first time without any warning or error. In the menu only "p" to print and "q" to quit will work!. 5.Now complete the functions given by their prototype: float freeSpace ();The function has to calculate the sum of the size component of all elements currently stored in the disk array. The function shall return the free space of the disk by the difference between the available total volume and the calculated sum. TEST: To test this function you only need to uncomment printing the "statusline" at the function actionmenu(). Compare the calculated value with a manual calculation of the example values given above. unsigned isBefore (DATE, DATE);The function checks if one date is before the other. There are 3 different possibilities which have to be handled. Imagine for example these 3 different combinations of values: ◦2010-01-01 : 2010-01-02 ◦2010-01-01 : 2010-02-01 ◦2010-01-01 : 2009-01-01 The function shall just return the result of the comparison. unsigned isEqual (DATE, DATE);The function checks if one date is equal to the other, all components have to be compared. The function shall just return the result of the comparison. int findByDate (DATE);As the array is should be kept in order (sorted by date) implement a binary search for a folder by its date here. You need only to adapt the binary search we used in the exercise. Use the 2 comparing functions above where appropriate. The function shall return the index of the element which was found or -1. TEST: Now you can try searching a folder by date via the "s" in the menu. Activate the corresponding part in the main function. int isSpaceLeft (FOLDER);This function compares the free space of the disk with the size of folder given with the parameter list. The function shall return 1 if there is enough space to add the folder, otherwise 0 (just the result of the comparison). void SortByDate ();This function shall implement the InsertionSort using the component date as key. Use the provided algorithm/souce code of the exercise as template. If you need a comparison between dates, use the function isBefore you have written again. void addFolder (FOLDER);The function has to check if the disk has additional capacities to add the new folder (number of folders and space left). If at least one of these conditions is false print an error message and return -1. Else there has to be added an other test to avoid 2 folder elements with the same date (use the findByDate function here. If there is no folder with the new date simply attach the new folder at the end of the array and call the sorting algorithm afterwards to keep the order in the array. TEST: Now you can try to add a folder via the "a" in the menu. Activate the corresponding part in the main function. void delDir (int);This function removes one element of the disk array. The input parameter contains the index of the element to delete. Deletion can simply be done by moving all elements at the right one to the left (overwriting the element to delete. The function may get a -1. This has to be checked first (certainly there is nothing to delete then!) Don't forget to decrement the counter of elements at the end. TEST: Now you can try to remove a folder by date via the "r" in the menu. Activate the corresponding part in the main function. unsigned findAllOfLocation(char[], FOLDER[]);This is an optional additional task: The function shall find all elements with the given value for the component location (first input parameter). The array elements which are found have to be added to the FOLDER array (second input parameter). As this parameter is an array we can use the result later in the main function. There kernel of function implements a modified linear search on the disk array (it does not stop if one element is found bat continues search until the location of all elements is checked). The finally function shall return the number of elements found in the disk array. TEST: Now you can try to add a folder by date via the "l" in the menu. Activate the corresponding part in the main function.

0 Answers   Siemens,


write a program that will read the temperature in Celsius and convert that into Fahrenheit.

1 Answers  


What is sizeof int in c?

0 Answers  






Read N characters in to an array . Use functions to do all problems and pass the address of array to function. 2. Enter alphanumeric characters and form 2 array alphaets and digits.Also print the count of each array.

0 Answers  


Three major criteria of scheduling.

1 Answers  


What are the parts of c program?

0 Answers  


What are the functions to open and close the file in c language?

0 Answers  


Reverse the bit order in a single macro. eg. i/p = 10010101 --> o/p = 10101001

2 Answers  


Hi, main() { } Is a user defined function or Built in Functionn

26 Answers   Honeywell, Yahoo,


Write a program to reverse a given number in c language?

0 Answers  


Categories