Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5162f41

Browse files
committed
"Find Median from Data Stream": variable name
1 parent 3e996a6 commit 5162f41

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

‎src/295.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ struct MedianFinder {
88
int minHeapCapacity;
99
int maxHeapSize;
1010
int minHeapSize;
11-
double medium;
11+
double median;
1212
};
1313

1414
void swap(int *a, int *b) {
@@ -91,7 +91,7 @@ struct MedianFinder* MedianFinderCreate() {
9191
mf->maxHeap[0] = mf->minHeap[0] = 0;
9292
mf->minHeapSize = mf->maxHeapSize = 0;
9393
mf->minHeapCapacity = mf->maxHeapCapacity = 1;
94-
mf->medium = 0;
94+
mf->median = 0;
9595
return mf;
9696
}
9797

@@ -100,15 +100,15 @@ void addNum(struct MedianFinder* mf, int num) {
100100
if (mf == NULL) return;
101101

102102
if (mf->maxHeapSize == mf->minHeapSize) {
103-
if (num > mf->medium) {
103+
if (num > mf->median) {
104104
addHeap(&mf->minHeap, &mf->minHeapSize, &mf->minHeapCapacity, num);
105105
siftUpMin(mf->minHeap, mf->minHeapSize);
106-
mf->medium = mf->minHeap[0];
106+
mf->median = mf->minHeap[0];
107107
}
108108
else {
109109
addHeap(&mf->maxHeap, &mf->maxHeapSize, &mf->maxHeapCapacity, num);
110110
siftUpMax(mf->maxHeap, mf->maxHeapSize);
111-
mf->medium = mf->maxHeap[0];
111+
mf->median = mf->maxHeap[0];
112112
}
113113
}
114114
else {
@@ -134,14 +134,14 @@ void addNum(struct MedianFinder* mf, int num) {
134134
siftDownMax(mf->maxHeap, mf->maxHeapSize);
135135
}
136136
}
137-
mf->medium = mf->maxHeap[0] + (mf->minHeap[0] - mf->maxHeap[0]) / 2.0;
137+
mf->median = mf->maxHeap[0] + (mf->minHeap[0] - mf->maxHeap[0]) / 2.0;
138138
}
139139
}
140140

141141
/** find the median of current data stream */
142142
double findMedian(struct MedianFinder* mf) {
143143
if (mf == NULL) return 0;
144-
return mf->medium;
144+
return mf->median;
145145
}
146146

147147
/** Deallocates memory previously allocated for the data structure. */

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /