1.用一个保存最小值,一个保存最小值的前驱
#include <stdio.h>
#include <stdlib.h>
typedef struct LNode
{
int data;
struct LNode* next;
}LNode,*LinkList;
LinkList CreateList()
{
LinkList L;
L = (LinkList)malloc(sizeof(LNode));
L->next = NULL;
LNode *q = L;
LNode *p;
int x;
scanf("%d",&x);
while(x != 999)
{
p = (struct LNode *)malloc(sizeof(LNode));
p->data = x;
p->next = NULL;
q->next = p;
q = p;
scanf("%d",&x);
}
return L;
}
void main()
{
LinkList a = (LinkList)malloc(sizeof(LNode));
a = CreateList();
LNode *p = a->next;
LNode *minpre = a;
LNode *min = a->next;
while(p->next != NULL)
{
if(p->next->data < min->data)
{
minpre = p;
min = p->next;
}
p = p->next;
}
minpre->next = min->next;
p = a->next;
while(p != NULL)
{
printf("%d ",p->data);
p = p->next;
}
printf("\n");
}