answersLogoWhite

0


Best Answer

To find the highest and lowest elements in a linked list, iterate the list and detect the highest and lowest elements. Details omitted ...

list *head; /* pointer to first element */

list *temp; /* temp pointer

list *high = null; /* pointer to high element */

list *low = null; /* pointer to low element */

for (temp=head; temp!=null; temp=temp->next) { /* iterate all elements */

if (temp == head ) { /* initial case */

high = low = temp; /* start accumulating results

} else { /* otherwise */

if (higher(temp, high) high = temp; /* choose higher */

if (lower(temp, low) low = temp; /* choose lower */

}

}

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Find the highest and lowest element from a linked list?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Algorithm for finding min element in a linked list?

In a linked list, there is no way to find the "min element" or any other element with a specific property except by walking through the entire list. Of course, you could store a pointer to the min element and update that each time the list changes (add ing or deleting an element), which makes the list less generic and a tiny bit slower but is worth it if you need this min element often.Pseudocode for finding the min element (I'm assuming you're storing values and you want the element with the lowest value):ptr_minelement = null;ptr_element = ptr_firstelement;while (ptr_element != null) {if (ptr_minelement == null) or (ptr_minelement->value > ptr_element->value)ptr_minelement = ptr_element;ptr_element = ptr_element->ptr_next;}


Explain the linked list and multi linked list structures?

I tried my best to explain all Linked List. For Single Linked List http://www.fansonnote.com/2012/02/single-linked-list/ For Double Linked List http://www.fansonnote.com/2012/02/double-linked-list/ For Multi Linked List http://www.fansonnote.com/2012/02/multi-linked-list/ Hope it will help. Thanks.


How do you find the HCF of all the numbers in an array java?

I guess you mean the highest common factor. Use a loop. Start assuming that the hcf is the first number in the array. Call this "result". Find the hcf of "result" and the second element, assign this to "result". Find the hcf of "result" and the third element, and copy this back to result, etc.


Disadvantages of circular link list as compared to singly link list?

As compared with doubly-linked lists, one disadvantage is that singly-linked lists can only be efficiently traversed in one direction. Finding the (n - 1)th element, given only a pointer to the nth, requires scanning the list from the first element up to the (n - 1)th. Thus (if memory is too limited to permit tricks such as creating a reversed list) to iterate over the entire list in reverse order would require n + (n - 1) + ... + 1 = n(n + 1)/2 link traversals, which grows quadratically with n. Obviously for a doubly-linked list the time merely grows linearly with n.A down-side of all linked lists versus arrays is that random access can be inefficient; the time taken to find an element with a randomly chosen index grows in direct proportion to the list's length (since we must scan from one of the ends). In contrast, an array allows us to index directly to the elements with simple pointer arithmetic, in a time independent of the array's size - at least in an idealised environment.


The minimum number of comparisons requied to find the second smallest element in a 1000 element array is?

1010

Related questions

How do you get the range of integer values?

The range of a set of numbers is the difference between the highest and lowest values. Find these and subtract the lowest from the highest.


Common operation of singly linked list?

Common operations on a singly linked list include insertion (at the beginning, end, or specific position), deletion (from the beginning, end, or specific position), traversal (visiting each node in the list), searching (finding a specific value), and updating (modifying the value of a node).


How do you find the median when theres four numbers?

When sorted lowest to highest (or highest to lowest) the median is (2nd number + 3rd number)/2


How find out the given five numbers is lowest as well as highest?

Any number can be the lowest as well the highest of a set only if all the numbers are the same.


How do you calculate range in mathformula for range?

Find the rangeset of data:88,76,59,39,20,85,94,20,67step 1: rearrange from lowest to highest20,20,39,59,67,76,85,88,94step 2: highest - lowest = range94 - 20Answer = 74basics:1.rearrange from lowest to highest2.highest - lowest = range


How do you find range in a set of numbers?

The first step is to sort the numbers from highest to lowest. The range is then the difference between the first and last numbers, or the highest and lowest.


Can you find out the highest and lowest note the trumpet play?

The lowest standard note on trumpet is the F-sharp below the staff. The highest note depends on the player.


How do you find a temperature range?

The highest temperature minus the lowest temperature is the temperature range. The temperature range is how many degrees is in between the highest and lowest temperatures.


How do you find the element with the largest volume?

Look for the one with the lowest density.


How do you find the lowest point on a linear graph?

Lines are infinite and so do not have a highest or lowest point. You need to have a curve to have a possible lowest point.


How do you find the range in box and whisker plot?

The highest and lowest numbers in a box and whisker plot are shown by the two dots at the end of the "whiskers". To find the range, you must subtract the highest number from the lowest number.


Why companies choose to use Excel min and max?

MIN finds the lowest value in a range and MAX finds the highest value in a range. Companies would be doing lots of things where they would need to find the highest or lowest value. They might want to find what the highest sales were in a year, or the lowest sales. See the related questions below.