c语言程序问题~

来源:百度知道 编辑:UC知道 时间:2024/06/06 00:38:42
题目:设一单向链表的头指针为head,链表的记录中包含着整数类型的key域,试设计算法,将此链表的记录按照key递增的次序进行排序。
我编了一下程序,却运行不了~请问错误在哪里?

#include <stdio.h>
#include <stdlib.h>

struct tagNode
{
int data;
struct tagNode *pNext;
};

typedef struct tagNode* pNode;
int i,j;
void paixv(pNode head){
pNode q=head->pNext;
int temp;
for( i=0;i<10;i++){
head=head->pNext;
for( j=i;j<9;j++)
if(head->data>q->pNext->data){
// q=head;
// head=head->pNext;
temp=head->data;
head->data=q->pNext->data;
q->pNext->data=temp;
q=q->pNext;
// head->pNext->pNext=q;

}
}
}

void print(pNode head){
for(i=0;i<10;i++){
printf("%d",head->pNext->data);
head=head->pNext;
}
}

void main(){
pNode head=(pNode)malloc(

怎么我把注释的那几行去掉,然后把尾段的if(i=0)改成if(i==0)就编译成功了!没问题啊!运行的了啊~

加了print(head)也行啊!会不会是你的编译软件有问题啊!我用的是《Turbo C/C++ for windows 集成实验与学习环境》这个软件