Comparing adjacent values in a file

• 02-09-2009
typhonius
Comparing adjacent values in a file
Hi all,
after a fair amount of help from a couple of guys on here *tips hat to Adak* and many hours hunched over my computer I've completed a problem I was set and added extra functions in for 'fun'.
Unfortunately I look at the next problem and find myself at a loss for which function I need to use.

I have two sets of data in a file, A and B. A is essentially just a numerical marker and B is the value assigned to that marker. B fluctuates, A rises +1 every time. I have managed to extract the data from the file (line by line) and then put it in a new file of the user's choice. However the task assigned was to do this yet in the middle, find out which are the peak values. For example, 0.1, 0.3, 0.5, 0.3, 0.7, 0.1, 0.2, 0.1.

In this example 0.5, 0.7 and 0.2 are the peak values. I was hoping you guys would be able to inform me of a function (or hack of a function) that compares two adjacent values.

• 02-09-2009
itCbitC
Forget about the coding part just yet; based on that dataset what do you think the algorithm should look like
• 02-09-2009
You wore out your welcome with me, Typhonius, or is it Typhos?

Imagine my surprise to see your same question, that I already answered complete with code, over on the dev shed C forum, two days later. :(

What's the deal here, you collect a bunch of answers to students assignments, and then sell them, or what?
• 02-09-2009
typhonius
I have used structs to take the values from the file and I assume I need to do something like

Code:

``` for(i = 0; i < num - 1; i++)   {       for(j = i + 1; j < num; j++)       if((i > j) && (i > k)```
I know that's horrible undefined code but I can't think of how to do it.
With help I managed a sort yesterday and I used a similar notation to that.
I think it was a bubble sort. It went through over and over comparing each element of the array to make an alphabetical list.
• 02-09-2009
typhonius
Quote:

You wore out your welcome with me, Typhonius, or is it Typhos?

Imagine my surprise to see your same question, that I already answered complete with code, over on the dev shed C forum, two days later. :(

What's the deal here, you collect a bunch of answers to students assignments, and then sell them, or what?

I'm not in devshed, I'm only on this one.
Must be mistaken identity :(
Sorry if there is confusion I'm genuinely only coding for me.

Edit: It may be one of my classmates?
• 02-09-2009
tabstop
So you need to stop typing and think for a little bit, I guess. What does it look like to get a peak? What changes when you hit a peak? Think graphically.

Once you have that then you can start looking at how to embody that in code.
• 02-09-2009
typhonius
Graphically the sign of the differential changes.

Going up a slope it would be a positive differential

Going down a slope it will be a negative differential
• 02-09-2009
tabstop
Quote:

Originally Posted by typhonius
Graphically the sign of the differential changes.

Going up a slope it would be a positive differential

Going down a slope it will be a negative differential

And you're done.
• 02-09-2009
iMalc
Quote:

Originally Posted by typhonius
Graphically the sign of the differential changes.

More specifically when the sign of the differential changes from + to - you have a peak. Changing from - to + would be a trough.

So, is it all clear now?
• 02-09-2009
typhonius
I can understand that if we had the equation of the line, but we don't have that.
We only have the values I mentioned :/
• 02-10-2009
matsp
Quote:

Originally Posted by typhonius
I can understand that if we had the equation of the line, but we don't have that.
We only have the values I mentioned :/

So, how would you solve this problem if you had the numbers written down on cards, where you had to deal with two cards at any time (for example one in your left hand and one in your right hand)? Using this method should work for your example.

--
Mats