단일 원형 연결리스트에서 정렬방법

wltjd666의 이미지

void SortByHp_SL(List *plist)
{
int hp = 0;
int num = plist->num;
int num2 = 0;

plist->cur = plist->head->next;
plist->sort = plist->head->next;

while (num > 0)
{
num2 = num;
while (num2 > 0)
{
if (hp > plist->cur->hp)
{
hp = plist->cur->hp;
plist->maxHp = plist->cur;
}
plist->cur->next;
num2--;
}

Swap(plist->maxHp, plist->sort);

plist->sort = plist->sort->next;
plist->cur = plist->cur->next;
num--;
}
}

void Swap(Node *first,Node *second)
{
struct champion temp = { 0, };

//maxHp의 데이터를 temp에 임시로 옮긴다.
temp.hp = first->hp;
temp.mp = first->mp;
temp.speed = first->speed;
temp.range = first->range;
strcpy(temp.name, first->name);
strcpy(temp.position, first->position);

//first의 데이터를 초기화한다.
first->hp = 0;
first->mp = 0;
first->speed = 0;
first->range = 0;
memset(first->name, 0, sizeof(first->name));
memset(first->position, 0, sizeof(first->position));

//second의 데이터를 first로 옮긴다.
first->hp = second->hp;
first->mp = second->mp;
first->range = second->range;
first->speed = second->speed;
strcpy(first->name, second->name);
strcpy(first->position, second->position);

//second의 데이터를 초기화한다.
second->hp = 0;
second->mp = 0;
second->speed = 0;
second->range = 0;
memset(second->name, 0, sizeof(second->name));
memset(second->position, 0, sizeof(second->position));

//temp의 데이터를 second로 옮긴다.
second->hp = temp.hp;
second->mp = temp.mp;
second->speed = temp.speed;
second->range = temp.range;
strcpy(second->name, temp.name);
strcpy(second->position, temp.position);
}

정렬이 안됩니다 뭐가 잘못된 걸까요?
참고로 Head 노드는 맨 앞이 아니라 맨 뒤에 있습니다.

bushi의 이미지

list.h 는 이중 연결 리스트의 간단한 구현이고,
champ1.c 는 리스트의 링크를 바꾸고,
champ2.c 는 새로운 헤드에 링크 하고,
champ3.c 는 (시도하신 것 처럼) 원소의 값을 바꿉니다.

댓글 첨부 파일: 
첨부파일 크기
Plain text icon list.h.txt933바이트
Plain text icon champ1.c.txt2.45 KB
Plain text icon champ2.c.txt2.73 KB
Plain text icon champ3.c.txt2.43 KB

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.