def bubble_sort(series, series2):
    """bubble_sort

    :param series: list of DICOM objects in input series
    :param series2: list of filenames corresponding to each
                    element in series
    
    Sort 'series' and 'series2' by the z-index of the
    ImagePositionPatient attribute of the elements in 
    'series'.
    """
    swapped = True
    while swapped:
        swapped = False
        for i in range(len(series) - 1):
            if series[i].ImagePositionPatient[2] > series[i + 1].ImagePositionPatient[2]:
                series[i], series[i + 1] = series[i + 1], series[i]
                series2[i], series2[i + 1] = series2[i + 1], series2[i]
                swapped = True
    return [series, series2]