Á´±íʵÏÖÅÅÐòËã·¨ ÏÂÔر¾ÎÄ

±±¾©Óʵç´óѧÐÅÏ¢ÓëͨÐŹ¤³ÌѧԺ

{ if (s->data < p->data) { comparision++; front->data = s->data; movement++; Node*x = p; Node*y = s; while (front->data < x->data) { comparision++; y->data = x->data; movement++; x = x->previor; y = y->previor; } y->data = front->data; movement++; } comparision++; p = p->next; s = s->next; } }

ðÅÝÅÅÐòº¯Êý£ºÃ¿Ò»´ÎÄÚÑ­»·±ß±È½Ï±ß½»»»£¬½«ÎÞÐòÇøÖÐ×î´óµÄÊý·ÅÈëÓÐÐòÇøÖУ¬

²¢¼Ç¼ÎÞÐòÔªËصķ¶Î§¡£µ±ÎÞÐòÔªËØÖ¸Ïòfrontʱ¼´ÕûÌåÅÅÐòÍê³É¡£

void LinkList::bubblesort() {

Node*s = front->previor; //³õʼ»¯ÎÞÐòÔªËØλÖà while (s != front) { Node*p = s; //±¾´ÎÎÞÐòÔªËØλÖà s = front; Node*x = front->next; Node*y = x->next; while (x != p) { if (x->data > y->data) { comparision++; front->data = x->data; x->data = y->data; y->data = front->data;

µÚ5Ò³

±±¾©Óʵç´óѧÐÅÏ¢ÓëͨÐŹ¤³ÌѧԺ

movement = movement + 3; s = x; //¸üÐÂÎÞÐòÔªËØλÖà } comparision++; x = x->next; y = y->next; } } }

¿ìËÙÅÅÐòº¯Êý£º¿ìËÙÅÅÐòº¯ÊýÊǸöµÝ¹éµ÷Óú¯Êý£¬¹Ø¼üÔÚÒ»´Î¿ìËÙÅÅÐòº¯ÊýµÄ

±àд¡£Ñ¡ÔñµÚÒ»¸öÔªËØ×÷Ϊ·ÖÇøµÄÖáÖµ£¬½«´ýÅÅÐòÔªËØ·Ö³É×óÓÒÁ½¸öÇøÓò£¬×óÇøµÄÔªËض¼±ÈÖáֵС£¬ÓұߵĶ¼¸ü´ó¡£

È»ºó·´¸´½øÐд˲Ù×÷£¬¼´¿ÉÍê³ÉÅÅÐò¡£¶ø½áÊøµÝ¹éµÄ¹Ø¼ü±ãÊÇ ×óÓÒ·Ö½ç½ÚµãÓÐÁËÖ±½ÓÇ°ºó¼Ì¹ØϵµÄʱºò¡£ void LinkList::Qsort(Node*x,Node*y) { if (x->previor != y) { Node*pivot = partion(x, y); Qsort(x, pivot->previor); Qsort(pivot->next, y); } }

Node* LinkList::partion(Node*first, Node*end) {

int basic = first->data; while (first != end) { while ((first != end) && (end->data >= basic)) { end = end->previor; comparision++; } comparision++; first->data = end->data; movement++; while ((first != end) && (first->data <= basic)) { first = first->next; comparision++; } comparision++; end->data = first->data;

µÚ6Ò³

±±¾©Óʵç´óѧÐÅÏ¢ÓëͨÐŹ¤³ÌѧԺ

}

movement++; }

first->data = basic; movement++; return first;

¼òµ¥Ñ¡ÔñÅÅÐòº¯Êý£ºÊǽ«´ýÅÅÐòÖÐ×îСµÄÔªËØ·ÅÖÃÐòÁÐ×îÇ°Ã棬Æä¹Ø¼üÊÇÏÈ

ͨ¹ýÑ­»·±È½ÏÈ·¶¨×îСԪËصÄλÖã¬ÔÙ½øÐÐÊý¾Ý½»»»£¬´Ó¶ø´ó´ó¼õÉÙÁËÔªËؽ»»»µÄ´ÎÊý¡£void LinkList::selectsort() {

Node*s = front->next; while (s != front->previor) { Node*p = s->next; Node*record = s; while (p != front) { Node*x = record; if (p->data < x->data) { comparision++; record = p; } comparision++; p = p->next; } if (record != s) { int a = record->data; record->data = s->data; s->data = a; movement = movement + 3; } s = s->next; } }

µÚ7Ò³

±±¾©Óʵç´óѧÐÅÏ¢ÓëͨÐŹ¤³ÌѧԺ

3. ³ÌÐòÔËÐнá¹û·ÖÎö

µÚ8Ò³