什么是未定义的引用此程序中的mergesort函数错误? [英] What is undefined reference to mergesort function error in this program?
本文介绍了什么是未定义的引用此程序中的mergesort函数错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#include<stdio.h>
#include<stdlib.h>
void merge(int left[],int right[],int a[],int half);
void mergesort(int a[],int n);
int main()
{
int a[6]={3,4,8,1,2,4}; int i;
mergesort(a,6);
for(i=0;i<6;i++)
printf("%d\t",a[i]);
return 0;
}
void merge(int left[],int right[],int a[],int half)
{
int i=0,j=0,k=0;
while(i<half&&j<half)
{
if(left[i]<right[j])
{
a[k]=left[i];
i++;
}
if(right[j]<left[i])
{
a[k]=right[j];
j++;
}
}
if(i==half)
{
for(j=j;j<half;j++)
{
a[k]=right[j];
k++;
}
}
if(j==half)
{
for(i=i;i<half;i++)
{
a[k]=left[i];
k++;
}
}
void mergesort(int a[],int n)
{
int half=n/2,i;
int left[half];
int right[half];
for(i=0;i<half;i++)
left[i]=a[i];
for(i=0;i<half;i++)
right[i]=a[i];
mergesort(left,half);
mergesort(right,half);
merge(left,right,a,half);
}
}
推荐答案
作为 Wes Aday [ ^ ]指出你在merge
函数中缺少一个右大括号,并且在mergesort
functtion
As Wes Aday[^] pointed out it looks like you're missing one closing brace in themerge
function and there's one extra aftermergesort
functtion
您在这里的问题仅仅是因为它比自己搜索更容易吗?
查看文档,谷歌查看错误消息。
认为我很粗鲁?这是让您练习和学习语言的典型作业。你不能让别人为你学习编程。
建议
- 学习语言。你不会总是问答答来学习这门语言。
- 你的语言文件是你的朋友。
- 错误信息是你的朋友。它告诉你你的代码不符合你的想法。
- 调试器是你的朋友。滥用调试器。
- 教程网站是你的朋友。
- 谷歌是你的朋友。你会发现有很多MergeSort snipsets。
我看到至少12个错误,其中大部分错误很多次。
- 程序永远不会结束。
- 程序松散了一些数据。
- ...
Are your asking here simply because it is easier than searching by yourself?
Look at documentation, google the error message.
Think I am rude ? This is typical homework to have you practice and learn the language. You can't have somebody to learn programming for you.
Advice
- Learn the language. You will not learn the language by always asking the answer.
- Your language documentation is your friend.
- The error message is your friend. it tells you that your code don't do what you think it is.
- The debugger is your friend. Abuse of debugger.
- Tutorial sites are your friends.
- Google is your friend. You will find there numerous MergeSort snipsets.
I see at least 12 errors and most of them many times.
- the program never end.
- the program loose some data.
- ...
这篇关于什么是未定义的引用此程序中的mergesort函数错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文