I have a struct declared like this:

struct Graphs

{

double x[100];

double y[100];

.

.

.

};

Graphs graph[10];

Graphs TotalGraph;

What I want to do now is to Add the 10 graphs to give me the sum in TotalGraph. The problem is however that not all the x-values are the same (but they are ordered from low to high), so you can not simply add the corresponding y-values. At the moment I put all the values in a large array, sort them using qsort, and then use the difference between two subsequent y-values to determine the total y-value at each discrete x-value. Although this works well enough, it's not fast enough.

Any ideas?

Both indexes start at 0. Inside a loop compare the two x values that are indexed. If they are the same, add the y's and increment BOTH indexes. If the two x's are different. Don't add and increment the ONLY index associated with the smaller x value. The loop terminates when either index value goes past the last allowed index (when it is > 99).

Any questions?