You are not logged in. Please login at www.codechef.com to post your questions!

×

Merge sort not running!

#include<stdio.h>
#include<conio.h>
#include<iostream>
#include<stdlib.h>
using namespace std;
int p[10]={31,2,15,3,77,12,89,98,43,34},q[10],k;
void merge(int,int,int,int);
void partition(int,int);

int main()
{
int i;
partition(0,9);
for(i=0;i<=9;i++)
{
    cout<<p[i]<<endl;
}   
return 0;
}

void partition(int x, int y)
{
if(x!=y)
{
    k=(x+y)/2;
    partition(x,k);
    partition(k+1,y);
    merge(x,k,k+1,y);
}
 }

void merge(int a, int b, int c, int d)
{
    int k=a,t=d;
    int i;
    for(i=k;i<=t;i++)
    {
        if(p[a]>p[c])
        {
            q[i]=p[c];
            c++;
        }
        else
        {
            q[i]=p[a];
            a++;
        }
    }   
    if(a<=b)
        q[d]=p[b];
    else 
        q[d]=p[d];

    for(i=0;i<=9;i++)
    {
        p[i]=q[i];
    }

 }

asked 30 Oct '14, 23:43

notequaltogeek's gravatar image

0★notequaltogeek
1
accept rate: 0%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×1,912
×22

question asked: 30 Oct '14, 23:43

question was seen: 431 times

last updated: 30 Oct '14, 23:43