下列程序是将带表头结点以单链表为存储结构的表进行简单选择排序
#include "stdafx.h" #include <stdio.h> #include <malloc.h> #include <stdlib.h> #include <iostream> using namespace std; typedef struct Node { int data; struct Node *next; }Node,*linklist; void Lselectsort(inklist head) { Node *p, *q,*r;V int temp; p=head; while ( (1) ) { r=p; q=p->next; while(q) { if(q->data<r->data) ( (2) ) q=q-> next;. } if( (3) ) { temp= =r-> data; r-> data=p-> data; p->data= =temp; } P= p->next; } } void main() { cout << "请输入待排序的序列: (用0结束)\n"; Node *p; int a; head=NULL; scanf("%d" ,&a); while (a>0) { p=( Node*)malloc(sizeof(Node));p-> data=a; p->next-head;head=p; scanf("%d",&a); } cout <<"排序后的序列如下: "; Lselectsor(head); p=head; while (p) { printf("%d\t", p-> data); p=p-> next; cout << "\n"; }