#include
#include
#include
typedef struct Node NodePtr;
struct Node{ / 定义链表结点数据结构 */
int Val;
NodePtr Next;
};
void BubbleSort(NodePtr&L);
void output(NodePtr head);
int main()
{
int N, M;
int i;
int long t;
NodePtr Head, Rear, Pre, Tmp;
srand((unsigned)time(&t));
Head = Rear = (NodePtr)malloc(sizeof(struct Node));
/* 为程序处理方便,构造表头空结点 */
Head->Next = NULL;
scanf("%d %d", &N, &M);
for(i=0;i/* 创建链表 */
Pre = (NodePtr)malloc(sizeof(struct Node)); /* 申请新结点 */
Pre->Next = NULL;
Pre->Val=rand()%1000;
Rear->Next=Pre; /* 新结点插入链表尾部 */
Rear = Pre;
}
/* 以下寻找M插入位置的前驱结点 */
Pre = Head;
while( Pre->Next != NULL &&Pre->Next->Valre = Pre->Next;
/* 以下插入M */
Tmp = (NodePtr)malloc(sizeof(struct Node)); /* 创建新结点 */
Tmp->Val = M;
Tmp->Next = Pre->Next; /* 插入新结点 */
Pre->Next = Tmp;
if(Pre == Rear); /* 插入表尾时,需修改Rear */
Rear = Tmp;
/* 以下输出插入后的链表结果 */
Tmp = Head->Next;
BubbleSort(Head);
output(Head);
return 0;
}
22行 if(Pre == Rear); 后面多了个分号