Merge sort help

  • Thread starter george2625
  • Start date
  • #1

Main Question or Discussion Point

please help me with a c code for the merge sort...... and i am getting a segmentation fault in running this selection sort,,, please help......

#include <stdio.h>

int main( )
{
int arr[10];
int i,j,temp;
for ( i = 0 ; i<10 ; i++ )
{
printf("enter the numbers: \n");
scanf("%d \n", arr);
}
for ( i = 0 ; i <8 ; i++ )
{
for ( j = i + 1 ; j <9 ; j++ )
{
if ( arr > arr[j] )
{
temp = arr ;
arr = arr[j] ;
arr[j] = temp ;
}
}
}
for ( i = 0 ; i <10 ; i++ )
printf("the sorted array is: %d \n", &arr);
return 0;
}
 

Answers and Replies

  • #2
uart
Science Advisor
2,776
9


please help me with a c code for the merge sort...... and i am getting a segmentation fault in running this selection sort,,, please help......

scanf("%d \n", arr);

The problem is in your scanf statement. Scanf needs a reference and "arr" is already de-referenced. You need to prefix it with "&".
 
  • #3
rcgldr
Homework Helper
8,653
502
You probably wanted those loops to be ... ; i < 9; ... and ... ; j < 10; .... Also this algorithm is not a merge sort, it's a bubble (down) sort.
 

Related Threads for: Merge sort help

  • Last Post
Replies
2
Views
3K
  • Last Post
Replies
1
Views
3K
  • Last Post
Replies
1
Views
1K
Replies
3
Views
447
  • Last Post
Replies
3
Views
2K
  • Last Post
Replies
3
Views
3K
  • Last Post
Replies
1
Views
1K
Replies
46
Views
7K
Top