SlideShare a Scribd company logo
1 of 5
Download to read offline
// c++ code for a Median of Integer Stream from Text File program
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
#include
double streamMedian(vector v, int size)
{
double* s = new double[size];
for (int i = 0; i < size; ++i)
{
s[i] = v[i];
}
for (int i = size - 1; i > 0; --i)
{
for (int j = 0; j < i; ++j)
{
if (s[j] > s[j+1])
{
double t = s[j];
s[j] = s[j+1];
s[j+1] = t;
}
}
}
double median = 0.0;
if ((size % 2) == 0)
{
median = (s[size/2] + s[(size/2) - 1])/2.0;
}
else
{
median = s[size/2];
}
return median;
}
int main()
{
int number;
double median;
std::vector v;
int count = 1;
ifstream myfile ("input.txt");
if (myfile.is_open())
{
while ( myfile >> number )
{
cout << "After reading " << count << " element of stream - ";
v.push_back(number);
for (int i = 0; i < v.size(); ++i)
{
cout << v[i] << " ";
}
cout << "-> ";
sort(v.begin(), v.end());
cout << "median - " << streamMedian(v,v.size()) << endl;
}
myfile.close();
}
return 0;
}
/*
input.txt
5
15
1
3
output:
After reading 1 element of stream - 5 -> median - 5
After reading 1 element of stream - 5 15 -> median - 10
After reading 1 element of stream - 5 15 1 -> median - 5
After reading 1 element of stream - 1 5 15 3 -> median - 4
*/
Solution
// c++ code for a Median of Integer Stream from Text File program
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
#include
double streamMedian(vector v, int size)
{
double* s = new double[size];
for (int i = 0; i < size; ++i)
{
s[i] = v[i];
}
for (int i = size - 1; i > 0; --i)
{
for (int j = 0; j < i; ++j)
{
if (s[j] > s[j+1])
{
double t = s[j];
s[j] = s[j+1];
s[j+1] = t;
}
}
}
double median = 0.0;
if ((size % 2) == 0)
{
median = (s[size/2] + s[(size/2) - 1])/2.0;
}
else
{
median = s[size/2];
}
return median;
}
int main()
{
int number;
double median;
std::vector v;
int count = 1;
ifstream myfile ("input.txt");
if (myfile.is_open())
{
while ( myfile >> number )
{
cout << "After reading " << count << " element of stream - ";
v.push_back(number);
for (int i = 0; i < v.size(); ++i)
{
cout << v[i] << " ";
}
cout << "-> ";
sort(v.begin(), v.end());
cout << "median - " << streamMedian(v,v.size()) << endl;
}
myfile.close();
}
return 0;
}
/*
input.txt
5
15
1
3
output:
After reading 1 element of stream - 5 -> median - 5
After reading 1 element of stream - 5 15 -> median - 10
After reading 1 element of stream - 5 15 1 -> median - 5
After reading 1 element of stream - 1 5 15 3 -> median - 4
*/

More Related Content

Similar to c++ code for a Median of Integer Stream from Text File program#.pdf

Need to make a flowchart for the following codepublic static voi.pdf
Need to make a flowchart for the following codepublic static voi.pdfNeed to make a flowchart for the following codepublic static voi.pdf
Need to make a flowchart for the following codepublic static voi.pdf
faktdeal
 
Hello My code prints but I need this exact code to print unt and hav.pdf
Hello My code prints but I need this exact code to print unt and hav.pdfHello My code prints but I need this exact code to print unt and hav.pdf
Hello My code prints but I need this exact code to print unt and hav.pdf
almonardfans
 
i need help fixing my program so that the user can input both uper and.pdf
i need help fixing my program so that the user can input both uper and.pdfi need help fixing my program so that the user can input both uper and.pdf
i need help fixing my program so that the user can input both uper and.pdf
shreeaadithyaacellso
 

Similar to c++ code for a Median of Integer Stream from Text File program#.pdf (20)

Practical basics on c++
Practical basics on c++Practical basics on c++
Practical basics on c++
 
Lab. Programs in C
Lab. Programs in CLab. Programs in C
Lab. Programs in C
 
Program presentation
Program presentationProgram presentation
Program presentation
 
Bcsl 033 data and file structures lab s2-2
Bcsl 033 data and file structures lab s2-2Bcsl 033 data and file structures lab s2-2
Bcsl 033 data and file structures lab s2-2
 
Rsa Signature: Behind The Scenes
Rsa Signature: Behind The Scenes Rsa Signature: Behind The Scenes
Rsa Signature: Behind The Scenes
 
ماترێکس به‌ کوردی ئارام
ماترێکس به‌ کوردی ئارامماترێکس به‌ کوردی ئارام
ماترێکس به‌ کوردی ئارام
 
8 arrays and pointers
8  arrays and pointers8  arrays and pointers
8 arrays and pointers
 
Need to make a flowchart for the following codepublic static voi.pdf
Need to make a flowchart for the following codepublic static voi.pdfNeed to make a flowchart for the following codepublic static voi.pdf
Need to make a flowchart for the following codepublic static voi.pdf
 
Hello My code prints but I need this exact code to print unt and hav.pdf
Hello My code prints but I need this exact code to print unt and hav.pdfHello My code prints but I need this exact code to print unt and hav.pdf
Hello My code prints but I need this exact code to print unt and hav.pdf
 
i need help fixing my program so that the user can input both uper and.pdf
i need help fixing my program so that the user can input both uper and.pdfi need help fixing my program so that the user can input both uper and.pdf
i need help fixing my program so that the user can input both uper and.pdf
 
PRINCE PRESENTATION(1).pptx
PRINCE PRESENTATION(1).pptxPRINCE PRESENTATION(1).pptx
PRINCE PRESENTATION(1).pptx
 
Include
IncludeInclude
Include
 
C lab excellent
C lab excellentC lab excellent
C lab excellent
 
C and Data Structures Lab Solutions
C and Data Structures Lab SolutionsC and Data Structures Lab Solutions
C and Data Structures Lab Solutions
 
C and Data Structures
C and Data Structures C and Data Structures
C and Data Structures
 
Ronak Kachhawa , BCA Third Year
Ronak Kachhawa , BCA Third YearRonak Kachhawa , BCA Third Year
Ronak Kachhawa , BCA Third Year
 
Lecture # 1 introduction revision - 1
Lecture # 1   introduction  revision - 1Lecture # 1   introduction  revision - 1
Lecture # 1 introduction revision - 1
 
Lecture # 1 - Introduction Revision - 1 OOPS.pptx
Lecture # 1 - Introduction  Revision - 1 OOPS.pptxLecture # 1 - Introduction  Revision - 1 OOPS.pptx
Lecture # 1 - Introduction Revision - 1 OOPS.pptx
 
02slide_accessible.pptx
02slide_accessible.pptx02slide_accessible.pptx
02slide_accessible.pptx
 
cosc 281 hw2
cosc 281 hw2cosc 281 hw2
cosc 281 hw2
 

More from aquastore223

1. How new modern materials prompted changes in architecture in the .pdf
1. How new modern materials prompted changes in architecture in the .pdf1. How new modern materials prompted changes in architecture in the .pdf
1. How new modern materials prompted changes in architecture in the .pdf
aquastore223
 
Sodium hydroxide, also known as lye and caustic s.pdf
                     Sodium hydroxide, also known as lye and caustic s.pdf                     Sodium hydroxide, also known as lye and caustic s.pdf
Sodium hydroxide, also known as lye and caustic s.pdf
aquastore223
 
The molecular orbital (MO) theory is a way of loo.pdf
                     The molecular orbital (MO) theory is a way of loo.pdf                     The molecular orbital (MO) theory is a way of loo.pdf
The molecular orbital (MO) theory is a way of loo.pdf
aquastore223
 
Unfortunately several cancers are not predictable with simple tests .pdf
Unfortunately several cancers are not predictable with simple tests .pdfUnfortunately several cancers are not predictable with simple tests .pdf
Unfortunately several cancers are not predictable with simple tests .pdf
aquastore223
 
The van t Hoff factor i (named after J. H. van t Hoff) is a meas.pdf
The van t Hoff factor i (named after J. H. van t Hoff) is a meas.pdfThe van t Hoff factor i (named after J. H. van t Hoff) is a meas.pdf
The van t Hoff factor i (named after J. H. van t Hoff) is a meas.pdf
aquastore223
 
Polar Bonds and Molecular Shape A polar molecule.pdf
                     Polar Bonds and Molecular Shape  A polar molecule.pdf                     Polar Bonds and Molecular Shape  A polar molecule.pdf
Polar Bonds and Molecular Shape A polar molecule.pdf
aquastore223
 
The good functioning of an economy depends on the proper functioning.pdf
The good functioning of an economy depends on the proper functioning.pdfThe good functioning of an economy depends on the proper functioning.pdf
The good functioning of an economy depends on the proper functioning.pdf
aquastore223
 
Stegosaurus dinosaur belonged to the late jurassic period i.e Kimmer.pdf
Stegosaurus dinosaur belonged to the late jurassic period i.e Kimmer.pdfStegosaurus dinosaur belonged to the late jurassic period i.e Kimmer.pdf
Stegosaurus dinosaur belonged to the late jurassic period i.e Kimmer.pdf
aquastore223
 
Tests of Controls in an Audit of Internal Control. The objective of .pdf
Tests of Controls in an Audit of Internal Control. The objective of .pdfTests of Controls in an Audit of Internal Control. The objective of .pdf
Tests of Controls in an Audit of Internal Control. The objective of .pdf
aquastore223
 

More from aquastore223 (20)

1. How new modern materials prompted changes in architecture in the .pdf
1. How new modern materials prompted changes in architecture in the .pdf1. How new modern materials prompted changes in architecture in the .pdf
1. How new modern materials prompted changes in architecture in the .pdf
 
1) cobalt iodide has an intense color, thus this colorless salt cann.pdf
1) cobalt iodide has an intense color, thus this colorless salt cann.pdf1) cobalt iodide has an intense color, thus this colorless salt cann.pdf
1) cobalt iodide has an intense color, thus this colorless salt cann.pdf
 
the hybridisation is sp2 since the electron cloud.pdf
                     the hybridisation is sp2 since the electron cloud.pdf                     the hybridisation is sp2 since the electron cloud.pdf
the hybridisation is sp2 since the electron cloud.pdf
 
Sodium hydroxide, also known as lye and caustic s.pdf
                     Sodium hydroxide, also known as lye and caustic s.pdf                     Sodium hydroxide, also known as lye and caustic s.pdf
Sodium hydroxide, also known as lye and caustic s.pdf
 
Hydrocrbon is the organic compound which containing only the atoms .pdf
   Hydrocrbon is the organic compound which containing only the atoms .pdf   Hydrocrbon is the organic compound which containing only the atoms .pdf
Hydrocrbon is the organic compound which containing only the atoms .pdf
 
No. In order for a substance to conduct electrici.pdf
                     No. In order for a substance to conduct electrici.pdf                     No. In order for a substance to conduct electrici.pdf
No. In order for a substance to conduct electrici.pdf
 
HCHO OS for H is +1, O is -2 there are two Hs o.pdf
                     HCHO OS for H is +1, O is -2 there are two Hs o.pdf                     HCHO OS for H is +1, O is -2 there are two Hs o.pdf
HCHO OS for H is +1, O is -2 there are two Hs o.pdf
 
The molecular orbital (MO) theory is a way of loo.pdf
                     The molecular orbital (MO) theory is a way of loo.pdf                     The molecular orbital (MO) theory is a way of loo.pdf
The molecular orbital (MO) theory is a way of loo.pdf
 
The electrons reach or give off a certain amount of energy and diffe.pdf
  The electrons reach or give off a certain amount of energy and diffe.pdf  The electrons reach or give off a certain amount of energy and diffe.pdf
The electrons reach or give off a certain amount of energy and diffe.pdf
 
Weak London disperision and dipole- dipoleModerate Hydrogen bond.pdf
Weak London disperision and dipole- dipoleModerate Hydrogen bond.pdfWeak London disperision and dipole- dipoleModerate Hydrogen bond.pdf
Weak London disperision and dipole- dipoleModerate Hydrogen bond.pdf
 
var min =0; var max=10; var tab = {}; var name; var score;.pdf
var min =0; var max=10; var tab = {}; var name; var score;.pdfvar min =0; var max=10; var tab = {}; var name; var score;.pdf
var min =0; var max=10; var tab = {}; var name; var score;.pdf
 
Unfortunately several cancers are not predictable with simple tests .pdf
Unfortunately several cancers are not predictable with simple tests .pdfUnfortunately several cancers are not predictable with simple tests .pdf
Unfortunately several cancers are not predictable with simple tests .pdf
 
The van t Hoff factor i (named after J. H. van t Hoff) is a meas.pdf
The van t Hoff factor i (named after J. H. van t Hoff) is a meas.pdfThe van t Hoff factor i (named after J. H. van t Hoff) is a meas.pdf
The van t Hoff factor i (named after J. H. van t Hoff) is a meas.pdf
 
Polar Bonds and Molecular Shape A polar molecule.pdf
                     Polar Bonds and Molecular Shape  A polar molecule.pdf                     Polar Bonds and Molecular Shape  A polar molecule.pdf
Polar Bonds and Molecular Shape A polar molecule.pdf
 
The good functioning of an economy depends on the proper functioning.pdf
The good functioning of an economy depends on the proper functioning.pdfThe good functioning of an economy depends on the proper functioning.pdf
The good functioning of an economy depends on the proper functioning.pdf
 
The answer is Yes, it is a reduction-oxidation reaction2 HNO2 + 2.pdf
The answer is Yes, it is a reduction-oxidation reaction2 HNO2 + 2.pdfThe answer is Yes, it is a reduction-oxidation reaction2 HNO2 + 2.pdf
The answer is Yes, it is a reduction-oxidation reaction2 HNO2 + 2.pdf
 
Stegosaurus dinosaur belonged to the late jurassic period i.e Kimmer.pdf
Stegosaurus dinosaur belonged to the late jurassic period i.e Kimmer.pdfStegosaurus dinosaur belonged to the late jurassic period i.e Kimmer.pdf
Stegosaurus dinosaur belonged to the late jurassic period i.e Kimmer.pdf
 
The answer is d- the hydrogen bonds in iceThe high heat of fusion.pdf
The answer is d- the hydrogen bonds in iceThe high heat of fusion.pdfThe answer is d- the hydrogen bonds in iceThe high heat of fusion.pdf
The answer is d- the hydrogen bonds in iceThe high heat of fusion.pdf
 
SolutionOption (a) will qualify as a database as dictionary is a .pdf
SolutionOption (a) will qualify as a database as dictionary is a .pdfSolutionOption (a) will qualify as a database as dictionary is a .pdf
SolutionOption (a) will qualify as a database as dictionary is a .pdf
 
Tests of Controls in an Audit of Internal Control. The objective of .pdf
Tests of Controls in an Audit of Internal Control. The objective of .pdfTests of Controls in an Audit of Internal Control. The objective of .pdf
Tests of Controls in an Audit of Internal Control. The objective of .pdf
 

Recently uploaded

SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
Peter Brusilovsky
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
EADTU
 
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonQUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
httgc7rh9c
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
EADTU
 
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MysoreMuleSoftMeetup
 
Orientation Canvas Course Presentation.pdf
Orientation Canvas Course Presentation.pdfOrientation Canvas Course Presentation.pdf
Orientation Canvas Course Presentation.pdf
Elizabeth Walsh
 

Recently uploaded (20)

AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
Introduction to TechSoup’s Digital Marketing Services and Use Cases
Introduction to TechSoup’s Digital Marketing  Services and Use CasesIntroduction to TechSoup’s Digital Marketing  Services and Use Cases
Introduction to TechSoup’s Digital Marketing Services and Use Cases
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonQUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
 
Play hard learn harder: The Serious Business of Play
Play hard learn harder:  The Serious Business of PlayPlay hard learn harder:  The Serious Business of Play
Play hard learn harder: The Serious Business of Play
 
How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17
 
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
 
Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Orientation Canvas Course Presentation.pdf
Orientation Canvas Course Presentation.pdfOrientation Canvas Course Presentation.pdf
Orientation Canvas Course Presentation.pdf
 
Michaelis Menten Equation and Estimation Of Vmax and Tmax.pptx
Michaelis Menten Equation and Estimation Of Vmax and Tmax.pptxMichaelis Menten Equation and Estimation Of Vmax and Tmax.pptx
Michaelis Menten Equation and Estimation Of Vmax and Tmax.pptx
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Ernest Hemingway's For Whom the Bell Tolls
Ernest Hemingway's For Whom the Bell TollsErnest Hemingway's For Whom the Bell Tolls
Ernest Hemingway's For Whom the Bell Tolls
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 

c++ code for a Median of Integer Stream from Text File program#.pdf

  • 1. // c++ code for a Median of Integer Stream from Text File program #include #include #include #include #include #include #include #include #include #include using namespace std; #include double streamMedian(vector v, int size) { double* s = new double[size]; for (int i = 0; i < size; ++i) { s[i] = v[i]; } for (int i = size - 1; i > 0; --i) { for (int j = 0; j < i; ++j) { if (s[j] > s[j+1]) { double t = s[j]; s[j] = s[j+1]; s[j+1] = t; } } } double median = 0.0; if ((size % 2) == 0)
  • 2. { median = (s[size/2] + s[(size/2) - 1])/2.0; } else { median = s[size/2]; } return median; } int main() { int number; double median; std::vector v; int count = 1; ifstream myfile ("input.txt"); if (myfile.is_open()) { while ( myfile >> number ) { cout << "After reading " << count << " element of stream - "; v.push_back(number); for (int i = 0; i < v.size(); ++i) { cout << v[i] << " "; } cout << "-> "; sort(v.begin(), v.end()); cout << "median - " << streamMedian(v,v.size()) << endl; } myfile.close(); } return 0; }
  • 3. /* input.txt 5 15 1 3 output: After reading 1 element of stream - 5 -> median - 5 After reading 1 element of stream - 5 15 -> median - 10 After reading 1 element of stream - 5 15 1 -> median - 5 After reading 1 element of stream - 1 5 15 3 -> median - 4 */ Solution // c++ code for a Median of Integer Stream from Text File program #include #include #include #include #include #include #include #include #include #include using namespace std; #include double streamMedian(vector v, int size) { double* s = new double[size]; for (int i = 0; i < size; ++i)
  • 4. { s[i] = v[i]; } for (int i = size - 1; i > 0; --i) { for (int j = 0; j < i; ++j) { if (s[j] > s[j+1]) { double t = s[j]; s[j] = s[j+1]; s[j+1] = t; } } } double median = 0.0; if ((size % 2) == 0) { median = (s[size/2] + s[(size/2) - 1])/2.0; } else { median = s[size/2]; } return median; } int main() { int number; double median; std::vector v; int count = 1; ifstream myfile ("input.txt"); if (myfile.is_open()) {
  • 5. while ( myfile >> number ) { cout << "After reading " << count << " element of stream - "; v.push_back(number); for (int i = 0; i < v.size(); ++i) { cout << v[i] << " "; } cout << "-> "; sort(v.begin(), v.end()); cout << "median - " << streamMedian(v,v.size()) << endl; } myfile.close(); } return 0; } /* input.txt 5 15 1 3 output: After reading 1 element of stream - 5 -> median - 5 After reading 1 element of stream - 5 15 -> median - 10 After reading 1 element of stream - 5 15 1 -> median - 5 After reading 1 element of stream - 1 5 15 3 -> median - 4 */