带头节点单链表
void simpleselectsort(LinkList& l)//简单选择排序
{ LinkList s;if (l->next == NULL || l->next->next == NULL)return;LinkList q = l->next;//第一个节点for (; q != NULL; q = q->next){int min = q->data;s = q;for (LinkList p=q->next;p!=NULL;p=p->next)//p初始化s后的第一个节点{if (min>p->data){min = p->data;s = p;//记录最小值节点}}if (s != q)//q不是最小值节点,交换数据{int t = s->data;s->data = q->data;q->data = t;}}
}
无头节点单链表
typedef struct LNode{int data;struct LNode *next}*Linklist;
void simpleselectSort(Linklist *&head)
{Linklist *p,*q,*s;int min,t;if(head==0 || head->next==0){return;}for(q=head;q!=0;q=q->next){min=q->data;s=q;for(p=q->next;p!=0;p=p->next){if(min>p->data){min=p->data;s=p;}}if(s!=q){t=s->data;s->data=q->data;q->data=t;}}
}