'How to sort List in Data Structure
I need to create an algorithm in java that sorts a list, I've created the part where the list is made, but I can't sort it, I have tried to add bubble sort and merge sort but none of them worked, here is my code, I would really appreciate the help.
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
class No{
int number;
No next;
public No(int number){
this.number = number;
}
}
class Lista{
No head;
public void add(int n){
if(head == null){
head = new No(n);
}else{
No temp = head;
while(temp.next != null){
temp = temp.next;
}
temp.next = new No(n);
}
}
public String toString(){
No temp = head;
String str = "";
while(temp != null){
str += temp.number+" ";
temp = temp.next;
}
return str;
}
}```
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
