WeixiangYan/CodeTransOcean huggingface dataset:
Task: Averages_Median

C: #include <stdio.h>
#include <stdlib.h>

typedef struct floatList {
    float *list;
    int   size;
} *FloatList;

int floatcmp( const void *a, const void *b) {
    if (*(const float *)a < *(const float *)b) return -1;
    else return *(const float *)a > *(const float *)b;
}

float median( FloatList fl )
{
    qsort( fl->list, fl->size, sizeof(float), floatcmp);
    return 0.5 * ( fl->list[fl->size/2] + fl->list[(fl->size-1)/2]);
}

int main()
{
    static float floats1[] = { 5.1, 2.6, 6.2, 8.8, 4.6, 4.1 };
    static struct floatList flist1 = { floats1, sizeof(floats1)/sizeof(float) };

    static float floats2[] = { 5.1, 2.6, 8.8, 4.6, 4.1 };
    static struct floatList flist2 = { floats2, sizeof(floats2)/sizeof(float) };

    printf("flist1 median is %7.2f\n", median(&flist1)); 
    printf("flist2 median is %7.2f\n", median(&flist2)); 
    return 0;
}


C++: #include <algorithm>



template <typename Iterator>
double median(Iterator begin, Iterator end) {
  
  Iterator middle = begin + (end - begin) / 2;

  
  std::nth_element(begin, middle, end);

  if ((end - begin) % 2 != 0) { 
    return *middle;
  } else { 
    
    Iterator lower_middle = std::max_element(begin, middle);
    return (*middle + *lower_middle) / 2.0;
  }
}

#include <iostream>

int main() {
  double a[] = {4.1, 5.6, 7.2, 1.7, 9.3, 4.4, 3.2};
  double b[] = {4.1, 7.2, 1.7, 9.3, 4.4, 3.2};

  std::cout << median(a+0, a + sizeof(a)/sizeof(a[0])) << std::endl; 
  std::cout << median(b+0, b + sizeof(b)/sizeof(b[0])) << std::endl; 

  return 0;
}
Task: Averages_Median

C: #include <stdio.h>
#include <stdlib.h>

typedef struct floatList {
    float *list;
    int   size;
} *FloatList;

int floatcmp( const void *a, const void *b) {
    if (*(const float *)a < *(const float *)b) return -1;
    else return *(const float *)a > *(const float *)b;
}

float median( FloatList fl )
{
    qsort( fl->list, fl->size, sizeof(float), floatcmp);
    return 0.5 * ( fl->list[fl->size/2] + fl->list[(fl->size-1)/2]);
}

int main()
{
    static float floats1[] = { 5.1, 2.6, 6.2, 8.8, 4.6, 4.1 };
    static struct floatList flist1 = { floats1, sizeof(floats1)/sizeof(float) };

    static float floats2[] = { 5.1, 2.6, 8.8, 4.6, 4.1 };
    static struct floatList flist2 = { floats2, sizeof(floats2)/sizeof(float) };

    printf("flist1 median is %7.2f\n", median(&flist1)); 
    printf("flist2 median is %7.2f\n", median(&flist2)); 
    return 0;
}





Java: 
public static double median(List<Double> list) {
    Collections.sort(list);
    return (list.get(list.size() / 2) + list.get((list.size() - 1) / 2)) / 2;
}
Task: Averages_Median

C: #include <stdio.h>
#include <stdlib.h>

typedef struct floatList {
    float *list;
    int   size;
} *FloatList;

int floatcmp( const void *a, const void *b) {
    if (*(const float *)a < *(const float *)b) return -1;
    else return *(const float *)a > *(const float *)b;
}

float median( FloatList fl )
{
    qsort( fl->list, fl->size, sizeof(float), floatcmp);
    return 0.5 * ( fl->list[fl->size/2] + fl->list[(fl->size-1)/2]);
}

int main()
{
    static float floats1[] = { 5.1, 2.6, 6.2, 8.8, 4.6, 4.1 };
    static struct floatList flist1 = { floats1, sizeof(floats1)/sizeof(float) };

    static float floats2[] = { 5.1, 2.6, 8.8, 4.6, 4.1 };
    static struct floatList flist2 = { floats2, sizeof(floats2)/sizeof(float) };

    printf("flist1 median is %7.2f\n", median(&flist1)); 
    printf("flist2 median is %7.2f\n", median(&flist2)); 
    return 0;
}







Python: def median(aray):
    srtd = sorted(aray)
    alen = len(srtd)
    return 0.5*( srtd[(alen-1)//2] + srtd[alen//2])

a = (4.1, 5.6, 7.2, 1.7, 9.3, 4.4, 3.2)
print a, median(a)
a = (4.1, 7.2, 1.7, 9.3, 4.4, 3.2)
print a, median(a)
Task: Averages_Median

C: #include <stdio.h>
#include <stdlib.h>

typedef struct floatList {
    float *list;
    int   size;
} *FloatList;

int floatcmp( const void *a, const void *b) {
    if (*(const float *)a < *(const float *)b) return -1;
    else return *(const float *)a > *(const float *)b;
}

float median( FloatList fl )
{
    qsort( fl->list, fl->size, sizeof(float), floatcmp);
    return 0.5 * ( fl->list[fl->size/2] + fl->list[(fl->size-1)/2]);
}

int main()
{
    static float floats1[] = { 5.1, 2.6, 6.2, 8.8, 4.6, 4.1 };
    static struct floatList flist1 = { floats1, sizeof(floats1)/sizeof(float) };

    static float floats2[] = { 5.1, 2.6, 8.8, 4.6, 4.1 };
    static struct floatList flist2 = { floats2, sizeof(floats2)/sizeof(float) };

    printf("flist1 median is %7.2f\n", median(&flist1)); 
    printf("flist2 median is %7.2f\n", median(&flist2)); 
    return 0;
}








VB: Private Function medianq(s As Variant) As Double
    Dim res As Double, tmp As Integer
    Dim l As Integer, k As Integer
    res = 0
    l = UBound(s): k = WorksheetFunction.Floor_Precise((l + 1) / 2, 1)
        If l Then
            res = quick_select(s, k)
            If l Mod 2 = 0 Then
                tmp = quick_select(s, k + 1)
                res = (res + tmp) / 2
            End If
        End If
    medianq = res
End Function
Public Sub main2()
    s = [{4, 2, 3, 5, 1, 6}]
    Debug.Print medianq(s)
End Sub
Task: Averages_Median


C++: #include <algorithm>



template <typename Iterator>
double median(Iterator begin, Iterator end) {
  
  Iterator middle = begin + (end - begin) / 2;

  
  std::nth_element(begin, middle, end);

  if ((end - begin) % 2 != 0) { 
    return *middle;
  } else { 
    
    Iterator lower_middle = std::max_element(begin, middle);
    return (*middle + *lower_middle) / 2.0;
  }
}

#include <iostream>

int main() {
  double a[] = {4.1, 5.6, 7.2, 1.7, 9.3, 4.4, 3.2};
  double b[] = {4.1, 7.2, 1.7, 9.3, 4.4, 3.2};

  std::cout << median(a+0, a + sizeof(a)/sizeof(a[0])) << std::endl; 
  std::cout << median(b+0, b + sizeof(b)/sizeof(b[0])) << std::endl; 

  return 0;
}


C#: using System;
using System.Linq;

namespace Test
{
    class Program
    {
        static void Main()
        {
            double[] myArr = new double[] { 1, 5, 3, 6, 4, 2 };

            myArr = myArr.OrderBy(i => i).ToArray();
            

            int mid = myArr.Length / 2;
            double median;

            if (myArr.Length % 2 == 0)
            {
                
                median = (myArr[mid] + myArr[mid - 1]) / 2.0;
            }
            else
            {
                
                median = myArr[mid];
            }

            Console.WriteLine(median);
            Console.ReadLine();
        }
    }
}
Task: Averages_Median


C++: #include <algorithm>



template <typename Iterator>
double median(Iterator begin, Iterator end) {
  
  Iterator middle = begin + (end - begin) / 2;

  
  std::nth_element(begin, middle, end);

  if ((end - begin) % 2 != 0) { 
    return *middle;
  } else { 
    
    Iterator lower_middle = std::max_element(begin, middle);
    return (*middle + *lower_middle) / 2.0;
  }
}

#include <iostream>

int main() {
  double a[] = {4.1, 5.6, 7.2, 1.7, 9.3, 4.4, 3.2};
  double b[] = {4.1, 7.2, 1.7, 9.3, 4.4, 3.2};

  std::cout << median(a+0, a + sizeof(a)/sizeof(a[0])) << std::endl; 
  std::cout << median(b+0, b + sizeof(b)/sizeof(b[0])) << std::endl; 

  return 0;
}




Java: 
public static double median(List<Double> list) {
    Collections.sort(list);
    return (list.get(list.size() / 2) + list.get((list.size() - 1) / 2)) / 2;
}
Task: Averages_Median


C++: #include <algorithm>



template <typename Iterator>
double median(Iterator begin, Iterator end) {
  
  Iterator middle = begin + (end - begin) / 2;

  
  std::nth_element(begin, middle, end);

  if ((end - begin) % 2 != 0) { 
    return *middle;
  } else { 
    
    Iterator lower_middle = std::max_element(begin, middle);
    return (*middle + *lower_middle) / 2.0;
  }
}

#include <iostream>

int main() {
  double a[] = {4.1, 5.6, 7.2, 1.7, 9.3, 4.4, 3.2};
  double b[] = {4.1, 7.2, 1.7, 9.3, 4.4, 3.2};

  std::cout << median(a+0, a + sizeof(a)/sizeof(a[0])) << std::endl; 
  std::cout << median(b+0, b + sizeof(b)/sizeof(b[0])) << std::endl; 

  return 0;
}






Python: def median(aray):
    srtd = sorted(aray)
    alen = len(srtd)
    return 0.5*( srtd[(alen-1)//2] + srtd[alen//2])

a = (4.1, 5.6, 7.2, 1.7, 9.3, 4.4, 3.2)
print a, median(a)
a = (4.1, 7.2, 1.7, 9.3, 4.4, 3.2)
print a, median(a)
Task: Averages_Median



C#: using System;
using System.Linq;

namespace Test
{
    class Program
    {
        static void Main()
        {
            double[] myArr = new double[] { 1, 5, 3, 6, 4, 2 };

            myArr = myArr.OrderBy(i => i).ToArray();
            

            int mid = myArr.Length / 2;
            double median;

            if (myArr.Length % 2 == 0)
            {
                
                median = (myArr[mid] + myArr[mid - 1]) / 2.0;
            }
            else
            {
                
                median = myArr[mid];
            }

            Console.WriteLine(median);
            Console.ReadLine();
        }
    }
}





Python: def median(aray):
    srtd = sorted(aray)
    alen = len(srtd)
    return 0.5*( srtd[(alen-1)//2] + srtd[alen//2])

a = (4.1, 5.6, 7.2, 1.7, 9.3, 4.4, 3.2)
print a, median(a)
a = (4.1, 7.2, 1.7, 9.3, 4.4, 3.2)
print a, median(a)
Task: Averages_Median



C#: using System;
using System.Linq;

namespace Test
{
    class Program
    {
        static void Main()
        {
            double[] myArr = new double[] { 1, 5, 3, 6, 4, 2 };

            myArr = myArr.OrderBy(i => i).ToArray();
            

            int mid = myArr.Length / 2;
            double median;

            if (myArr.Length % 2 == 0)
            {
                
                median = (myArr[mid] + myArr[mid - 1]) / 2.0;
            }
            else
            {
                
                median = myArr[mid];
            }

            Console.WriteLine(median);
            Console.ReadLine();
        }
    }
}






VB: Private Function medianq(s As Variant) As Double
    Dim res As Double, tmp As Integer
    Dim l As Integer, k As Integer
    res = 0
    l = UBound(s): k = WorksheetFunction.Floor_Precise((l + 1) / 2, 1)
        If l Then
            res = quick_select(s, k)
            If l Mod 2 = 0 Then
                tmp = quick_select(s, k + 1)
                res = (res + tmp) / 2
            End If
        End If
    medianq = res
End Function
Public Sub main2()
    s = [{4, 2, 3, 5, 1, 6}]
    Debug.Print medianq(s)
End Sub
Task: Averages_Median







Python: def median(aray):
    srtd = sorted(aray)
    alen = len(srtd)
    return 0.5*( srtd[(alen-1)//2] + srtd[alen//2])

a = (4.1, 5.6, 7.2, 1.7, 9.3, 4.4, 3.2)
print a, median(a)
a = (4.1, 7.2, 1.7, 9.3, 4.4, 3.2)
print a, median(a)


VB: Private Function medianq(s As Variant) As Double
    Dim res As Double, tmp As Integer
    Dim l As Integer, k As Integer
    res = 0
    l = UBound(s): k = WorksheetFunction.Floor_Precise((l + 1) / 2, 1)
        If l Then
            res = quick_select(s, k)
            If l Mod 2 = 0 Then
                tmp = quick_select(s, k + 1)
                res = (res + tmp) / 2
            End If
        End If
    medianq = res
End Function
Public Sub main2()
    s = [{4, 2, 3, 5, 1, 6}]
    Debug.Print medianq(s)
End Sub
Task: Averages_Median


C++: #include <algorithm>



template <typename Iterator>
double median(Iterator begin, Iterator end) {
  
  Iterator middle = begin + (end - begin) / 2;

  
  std::nth_element(begin, middle, end);

  if ((end - begin) % 2 != 0) { 
    return *middle;
  } else { 
    
    Iterator lower_middle = std::max_element(begin, middle);
    return (*middle + *lower_middle) / 2.0;
  }
}

#include <iostream>

int main() {
  double a[] = {4.1, 5.6, 7.2, 1.7, 9.3, 4.4, 3.2};
  double b[] = {4.1, 7.2, 1.7, 9.3, 4.4, 3.2};

  std::cout << median(a+0, a + sizeof(a)/sizeof(a[0])) << std::endl; 
  std::cout << median(b+0, b + sizeof(b)/sizeof(b[0])) << std::endl; 

  return 0;
}







VB: Private Function medianq(s As Variant) As Double
    Dim res As Double, tmp As Integer
    Dim l As Integer, k As Integer
    res = 0
    l = UBound(s): k = WorksheetFunction.Floor_Precise((l + 1) / 2, 1)
        If l Then
            res = quick_select(s, k)
            If l Mod 2 = 0 Then
                tmp = quick_select(s, k + 1)
                res = (res + tmp) / 2
            End If
        End If
    medianq = res
End Function
Public Sub main2()
    s = [{4, 2, 3, 5, 1, 6}]
    Debug.Print medianq(s)
End Sub
Task: Averages_Median



C#: using System;
using System.Linq;

namespace Test
{
    class Program
    {
        static void Main()
        {
            double[] myArr = new double[] { 1, 5, 3, 6, 4, 2 };

            myArr = myArr.OrderBy(i => i).ToArray();
            

            int mid = myArr.Length / 2;
            double median;

            if (myArr.Length % 2 == 0)
            {
                
                median = (myArr[mid] + myArr[mid - 1]) / 2.0;
            }
            else
            {
                
                median = myArr[mid];
            }

            Console.WriteLine(median);
            Console.ReadLine();
        }
    }
}



Java: 
public static double median(List<Double> list) {
    Collections.sort(list);
    return (list.get(list.size() / 2) + list.get((list.size() - 1) / 2)) / 2;
}
Task: Averages_Median





Java: 
public static double median(List<Double> list) {
    Collections.sort(list);
    return (list.get(list.size() / 2) + list.get((list.size() - 1) / 2)) / 2;
}



Python: def median(aray):
    srtd = sorted(aray)
    alen = len(srtd)
    return 0.5*( srtd[(alen-1)//2] + srtd[alen//2])

a = (4.1, 5.6, 7.2, 1.7, 9.3, 4.4, 3.2)
print a, median(a)
a = (4.1, 7.2, 1.7, 9.3, 4.4, 3.2)
print a, median(a)
Task: Averages_Median





Java: 
public static double median(List<Double> list) {
    Collections.sort(list);
    return (list.get(list.size() / 2) + list.get((list.size() - 1) / 2)) / 2;
}




VB: Private Function medianq(s As Variant) As Double
    Dim res As Double, tmp As Integer
    Dim l As Integer, k As Integer
    res = 0
    l = UBound(s): k = WorksheetFunction.Floor_Precise((l + 1) / 2, 1)
        If l Then
            res = quick_select(s, k)
            If l Mod 2 = 0 Then
                tmp = quick_select(s, k + 1)
                res = (res + tmp) / 2
            End If
        End If
    medianq = res
End Function
Public Sub main2()
    s = [{4, 2, 3, 5, 1, 6}]
    Debug.Print medianq(s)
End Sub
Task: Averages_Median

C: #include <stdio.h>
#include <stdlib.h>

typedef struct floatList {
    float *list;
    int   size;
} *FloatList;

int floatcmp( const void *a, const void *b) {
    if (*(const float *)a < *(const float *)b) return -1;
    else return *(const float *)a > *(const float *)b;
}

float median( FloatList fl )
{
    qsort( fl->list, fl->size, sizeof(float), floatcmp);
    return 0.5 * ( fl->list[fl->size/2] + fl->list[(fl->size-1)/2]);
}

int main()
{
    static float floats1[] = { 5.1, 2.6, 6.2, 8.8, 4.6, 4.1 };
    static struct floatList flist1 = { floats1, sizeof(floats1)/sizeof(float) };

    static float floats2[] = { 5.1, 2.6, 8.8, 4.6, 4.1 };
    static struct floatList flist2 = { floats2, sizeof(floats2)/sizeof(float) };

    printf("flist1 median is %7.2f\n", median(&flist1)); 
    printf("flist2 median is %7.2f\n", median(&flist2)); 
    return 0;
}






PHP: function median($arr)
{
    sort($arr);
    $count = count($arr); //count the number of values in array
    $middleval = floor(($count-1)/2); // find the middle value, or the lowest middle value
    if ($count % 2) { // odd number, middle is the median
        $median = $arr[$middleval];
    } else { // even number, calculate avg of 2 medians
        $low = $arr[$middleval];
        $high = $arr[$middleval+1];
        $median = (($low+$high)/2);
    }
    return $median;
}

echo median(array(4.1, 5.6, 7.2, 1.7, 9.3, 4.4, 3.2)) . "\n";  // 4.4
echo median(array(4.1, 7.2, 1.7, 9.3, 4.4, 3.2)) . "\n";       // 4.25
Task: Averages_Median



C#: using System;
using System.Linq;

namespace Test
{
    class Program
    {
        static void Main()
        {
            double[] myArr = new double[] { 1, 5, 3, 6, 4, 2 };

            myArr = myArr.OrderBy(i => i).ToArray();
            

            int mid = myArr.Length / 2;
            double median;

            if (myArr.Length % 2 == 0)
            {
                
                median = (myArr[mid] + myArr[mid - 1]) / 2.0;
            }
            else
            {
                
                median = myArr[mid];
            }

            Console.WriteLine(median);
            Console.ReadLine();
        }
    }
}




PHP: function median($arr)
{
    sort($arr);
    $count = count($arr); //count the number of values in array
    $middleval = floor(($count-1)/2); // find the middle value, or the lowest middle value
    if ($count % 2) { // odd number, middle is the median
        $median = $arr[$middleval];
    } else { // even number, calculate avg of 2 medians
        $low = $arr[$middleval];
        $high = $arr[$middleval+1];
        $median = (($low+$high)/2);
    }
    return $median;
}

echo median(array(4.1, 5.6, 7.2, 1.7, 9.3, 4.4, 3.2)) . "\n";  // 4.4
echo median(array(4.1, 7.2, 1.7, 9.3, 4.4, 3.2)) . "\n";       // 4.25
Task: Averages_Median


C++: #include <algorithm>



template <typename Iterator>
double median(Iterator begin, Iterator end) {
  
  Iterator middle = begin + (end - begin) / 2;

  
  std::nth_element(begin, middle, end);

  if ((end - begin) % 2 != 0) { 
    return *middle;
  } else { 
    
    Iterator lower_middle = std::max_element(begin, middle);
    return (*middle + *lower_middle) / 2.0;
  }
}

#include <iostream>

int main() {
  double a[] = {4.1, 5.6, 7.2, 1.7, 9.3, 4.4, 3.2};
  double b[] = {4.1, 7.2, 1.7, 9.3, 4.4, 3.2};

  std::cout << median(a+0, a + sizeof(a)/sizeof(a[0])) << std::endl; 
  std::cout << median(b+0, b + sizeof(b)/sizeof(b[0])) << std::endl; 

  return 0;
}





PHP: function median($arr)
{
    sort($arr);
    $count = count($arr); //count the number of values in array
    $middleval = floor(($count-1)/2); // find the middle value, or the lowest middle value
    if ($count % 2) { // odd number, middle is the median
        $median = $arr[$middleval];
    } else { // even number, calculate avg of 2 medians
        $low = $arr[$middleval];
        $high = $arr[$middleval+1];
        $median = (($low+$high)/2);
    }
    return $median;
}

echo median(array(4.1, 5.6, 7.2, 1.7, 9.3, 4.4, 3.2)) . "\n";  // 4.4
echo median(array(4.1, 7.2, 1.7, 9.3, 4.4, 3.2)) . "\n";       // 4.25
Task: Averages_Median





Java: 
public static double median(List<Double> list) {
    Collections.sort(list);
    return (list.get(list.size() / 2) + list.get((list.size() - 1) / 2)) / 2;
}


PHP: function median($arr)
{
    sort($arr);
    $count = count($arr); //count the number of values in array
    $middleval = floor(($count-1)/2); // find the middle value, or the lowest middle value
    if ($count % 2) { // odd number, middle is the median
        $median = $arr[$middleval];
    } else { // even number, calculate avg of 2 medians
        $low = $arr[$middleval];
        $high = $arr[$middleval+1];
        $median = (($low+$high)/2);
    }
    return $median;
}

echo median(array(4.1, 5.6, 7.2, 1.7, 9.3, 4.4, 3.2)) . "\n";  // 4.4
echo median(array(4.1, 7.2, 1.7, 9.3, 4.4, 3.2)) . "\n";       // 4.25
Task: Averages_Median






PHP: function median($arr)
{
    sort($arr);
    $count = count($arr); //count the number of values in array
    $middleval = floor(($count-1)/2); // find the middle value, or the lowest middle value
    if ($count % 2) { // odd number, middle is the median
        $median = $arr[$middleval];
    } else { // even number, calculate avg of 2 medians
        $low = $arr[$middleval];
        $high = $arr[$middleval+1];
        $median = (($low+$high)/2);
    }
    return $median;
}

echo median(array(4.1, 5.6, 7.2, 1.7, 9.3, 4.4, 3.2)) . "\n";  // 4.4
echo median(array(4.1, 7.2, 1.7, 9.3, 4.4, 3.2)) . "\n";       // 4.25


Python: def median(aray):
    srtd = sorted(aray)
    alen = len(srtd)
    return 0.5*( srtd[(alen-1)//2] + srtd[alen//2])

a = (4.1, 5.6, 7.2, 1.7, 9.3, 4.4, 3.2)
print a, median(a)
a = (4.1, 7.2, 1.7, 9.3, 4.4, 3.2)
print a, median(a)
Task: Averages_Median






PHP: function median($arr)
{
    sort($arr);
    $count = count($arr); //count the number of values in array
    $middleval = floor(($count-1)/2); // find the middle value, or the lowest middle value
    if ($count % 2) { // odd number, middle is the median
        $median = $arr[$middleval];
    } else { // even number, calculate avg of 2 medians
        $low = $arr[$middleval];
        $high = $arr[$middleval+1];
        $median = (($low+$high)/2);
    }
    return $median;
}

echo median(array(4.1, 5.6, 7.2, 1.7, 9.3, 4.4, 3.2)) . "\n";  // 4.4
echo median(array(4.1, 7.2, 1.7, 9.3, 4.4, 3.2)) . "\n";       // 4.25



VB: Private Function medianq(s As Variant) As Double
    Dim res As Double, tmp As Integer
    Dim l As Integer, k As Integer
    res = 0
    l = UBound(s): k = WorksheetFunction.Floor_Precise((l + 1) / 2, 1)
        If l Then
            res = quick_select(s, k)
            If l Mod 2 = 0 Then
                tmp = quick_select(s, k + 1)
                res = (res + tmp) / 2
            End If
        End If
    medianq = res
End Function
Public Sub main2()
    s = [{4, 2, 3, 5, 1, 6}]
    Debug.Print medianq(s)
End Sub