please help me conver to MIPS from code C HeapSort as below

This topic contains 0 replies, has 1 voice, and was last updated by  peterhh11 5 years, 11 months ago.

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #31385

    peterhh11
    Member

    include<iostream>

    #include<conio.h>

    using namespace std;

    void shift(int a[], int i, int n){

        int j = 2 * i;

        int k = a;
        while(j <= n){

            if(j<n && a[j] < a[j+1])

                j++;

            if( k >= a[j])

                break;

            else {

                a[j/2] = a[j];

                a[j] = k;

                j *= 2;

            }

        }

    }

    void makeHeap(int a[], int n){

        int i;

        for (i=n/2;i>=0;i–)

            shift(a,i,n-1);

    }

    void heapSort(int a[], int n){

        makeHeap(a,n);

        for (int k=n-2;k>=0;k–){

    int c;

    c=a[0];

    a[0]=a[k+1];

    a[k+1]=c;

            shift(a,0,k);

        }

    }

    int main(){

    cout<<“nhap so phan tu cua mangn”;

    int n;

    cin>>n;

    int array[n];

    cout<<“nhap mang:”;

    for(int i=0;i<n;i++){

    cin>>array;

    cout<<” “;

    }

    cout<<endl;

    heapSort(array,n);

    cout<<“mang sau khi da sap xep:”;

    for(int i=0;i<n;i++){

    cout<<array<<” “;

    }

    return 0;

    }

Viewing 1 post (of 1 total)
You must be logged in to reply to this topic.