Juanka
- 37
- 0
Anyone familiar with a bubble sort? and if so how to implement it?
The discussion revolves around the implementation of bubble sort algorithms, particularly in the context of sorting one array while maintaining the association with another array. Participants explore the mechanics of bubble sort, share implementation details, and address specific coding challenges related to sorting paired data.
Participants generally agree on the need to sort the y array while maintaining the relationship with the x array. However, there is disagreement regarding the specific implementation details and the source of errors in the provided code.
There are unresolved issues regarding the specific implementation of the bubble sort algorithm, particularly in the context of maintaining paired data. The discussion does not clarify all assumptions or dependencies related to the sorting process.
Juanka said:Anyone familiar with a bubble sort?
and if so how to implement it?
function y= bubble(x,y)
n = length(x);
for k = 1:n-1
for j = 1:n-k
if(x(j)> x(j+1))
temp = x(j);
x(j) = x(j+1);
x(j+1) = temp;
temp = y(j);
y(j) = y(j+1);
y(j+1) = temp;
end % if
end % for
end % for
y = x;
Juanka said:I am having a problem