기수 정렬에 대한 이해가 안되었습니다. 나는 더 이상 글자가 남지 않을 때까지 오른쪽에서 왼쪽으로 정렬하는 것과 같은 단어의 마지막 글자를 분류해야합니다.Java에서 역순으로 기수 정렬
이
바 고양이 사과 버그 톱니 케이 퍼 뿔 발목 곰 같은 텍스트 파일보기
이
발목 뿔,536 같은 내 출력사과 바 곰 버그 케이 퍼 고양이 톱니
하지만이
바 버그 고양이 톱니 곰 발목 사과 케이 퍼 같은 출력을 얻을 수 있겠 달구어
올바른 코드가있는 것 같아 보이지만 방해가되어서 무엇을해야할지 모르겠습니다. 내가 무슨 짓을했는지 코드가 도움이 올바른 방향으로 여기
날 지점 얻을 수 있다면 크게
RadixSort.java
public class RadixSort {
public static void main(String[]args) throws FileNotFoundException{
Linkedlist[] allNameLinkedList = new Linkedlist[26]; // create an array
of LinkedList for 26 letters in alphabets
int count = 0;
// initialize all the elements in the array to new LinkedList
for (int i = 0; i < allNameLinkedList.length; i++) {
allNameLinkedList[i] = new Linkedlist();
}
Scanner scan = new Scanner(new File("words.txt"));
while(scan.hasNextLine())
{
String currentname = scan.nextLine();
for(int i = 0; i < 26; i++){
if(currentname.charAt(2) == (char)(i+97))
{
allNameLinkedList[i].addNodeToTheEndOfTheList(currentname);
}
}
count++;
}
// copy sorted nodes to new LinkedList called container
Linkedlist container = new Linkedlist();
for (int i = 0; i < 26; i++) {
Node n = allNameLinkedList[i].front;
while(n != null){
container.addNodeToTheEndOfTheList(n.name);
n = n.next;
}
}
// empty all the elements of array
for (int i = 0; i < allNameLinkedList.length; i++) {
allNameLinkedList[i] = new Linkedlist();
}
Node m = container.front;
while(m!=null)
{
String currentname = m.name;
for(int i = 0; i < 26; i++){
if(currentname.charAt(1) == (char)(i+97))
{
allNameLinkedList[i].addNodeToTheEndOfTheList(currentname);
}
}
m = m.next;
count++;
}
container = new Linkedlist();
for (int i = 0; i < 26; i++) {
m = allNameLinkedList[i].front;
while(m!=null){
container.addNodeToTheEndOfTheList(m.name);
m = m.next;
}
}
for (int i = 0; i < allNameLinkedList.length; i++) {
allNameLinkedList[i] = new Linkedlist();
}
m = container.front;
while(m!=null)
{
String currentname = m.name;
for(int i = 0; i < 26; i++){
if(currentname.charAt(0) == (char)(i+97))
{
allNameLinkedList[i].addNodeToTheEndOfTheList(currentname);
}
}
m = m.next;
count++;
}
container = new Linkedlist();
for (int i = 0; i < 26; i++) {
m = allNameLinkedList[i].front;
while(m!=null){
System.out.println(m.name);
container.addNodeToTheEndOfTheList(m.name);
m = m.next;
}
}
scan.close();
System.out.println("The total number of comparisions was :"+count);
}
}
나중에 참조 할 수 있도록 잘못 작성된 내용을 적은 양의 텍스트로 보여주는 간단한 자체 포함 된 올바른 예제를 포함하는 것이 좋습니다. 여기에는 연결된 목록 코드가 포함됩니다. 원하는 내용에 대한 자세한 내용은 http://sscce.org/ – dddJewelsbbb
코드가 너무 많아서 질문을 이해하지 못했지만 단어를 정렬했는데 실제로 필요한 것은 무엇입니까? '결과물은 기수 정렬과 관련이 있습니까? – Shadov