Though the question has been answered, 'where to start' is important.
Before you start coding, always think out what you want the program to do on paper.
For this particular problem, what you need to think about is:
If I can find the largest number, how can I use that information or process to find the second largest number?
Assuming you compare the current maximum to another number, you then update the variable with the largest number.
But that means that the number just discarded is (by definition) the second largest number yet encountered.
But you're not done yet. As Rashakil Fol pointed out, there are additional cases, where the new number may be smaller than the maxiumum but smaller than the second, so you have to account for that.
And, what if you have equal numbers for your maximum or second largest?
but what if the 1st number in the array is the largest? so max should be assigned to 0 , right? if max is intialised as the first element of the array, then if the 1st element is the largest then 2nd largest will also be that number only, right?
but is max is assigned to 0 then the program wont work with negetive integers ! any possible solutions?
Assign the largest number initially, to the value of the first element of the array. Assign the 2nd largest number initially to INT_MIN (your compilers macro for the least possible value for an integer.
That makes the "mouth" for trapping the numbered values you want in the array, suitable.
(Your compiler may call it MIN_INT or something different, but you can check in the header file, limits.h, and you should include it).
If you get "stuck" in a really sticky logic situation in this problem, you can always just sort the values in the array, say descending, and then count down by one, for every new value in the array. That way duplicates don't goof it up.
I am working creating a fully encapsulated, homogeneous singly linked data structure. The Listing class and SinglyLinkedList class that are part of the whole application compile fine, but the problem ...