0 like 0 dislike
378 views

Maximum heap

 

請根據以下步驟完成這個作業:

  1. 宣高函數 int N(int array[10000],int n)
  2. 執行以下動作
    1. 如果array[n]不等於0的話,就回傳1+N(array, (n+1)*2-1)+N(array, (n+1)*2)。
    2. 如果array[n]等於0的話就回傳0。
  3. 宣告函數void insert(int array[10000], int n,int j)
  4. 執行以下動作
    1. 如果array[j]等於0的話,就作array[j]=n,然後結束函數。
    2. 如果 array[j]小於n的話,就交換array[j]跟n。
    3. 如果N(array,(j+1)*2-1)大於N(array,(j+1)*2),就呼叫insert(array,n,(j+1)*2)。
    4. 如果N(array,(j+1)*2-1)小於等於N(array,(j+1)*2),就呼叫insert(array,n,(j+1)*2-1)。
  5. 宣告函數 int Delete(int array[10000], int n)
  6. 執行以下動作
    1. 如果 a[n] 等於 0 ,就結束函數
    2. 令變數temp=array[n]。
    3. 如果array[(n+1)*2-1]大於等於array[(n+1)*2],就執行array[n]=Delete(array,(n+1)*2-1)。
    4. 如果array[(n+1)*2-1]小於array[(n+1)*2],就執行array[n]=Delete(array,(n+1)*2)。
    5. 回傳temp。
  7. 宣告函數 int main()
  8. 函數做以下動作
    1. 宣告一個陣列 int array[10000]={0}。
    2. 亂數產生一個變數 n(n>0)。
    3. 呼叫 insert(array,n,0)。
    4. 重複步驟B跟步驟C十次。
    5. 執行temp=delete(array,0),並印出temp的值。
    6. 如果temp不等於0就回到步驟E。
[Exercise] Essay (Open question) - asked in 2016-1 程式設計(一)AC by (18k points)
ID: 20974 - Available when: Unlimited - Due to: Unlimited

reshown by | 378 views

16 Answers

0 like 0 dislike
Hidden content!
#include<stdio.h>

#include<stdlib.h>

#include<string.h>

#include<ctype.h>



int N(int array[10000],int N)

{
*** * **** * * * ** *** * *
* ** * * ** * * * ** *** *** ** * * * ****** *** 1+N(array,(n+1)*2-1)+N(array,(n+1)*2);
**** * *** * * *** if(array[n]==0)
* * * ** *** * ** * * **** * * ** **** ***** 0;

}



void insert(int array[10000], int n,int j)

{
* *** * * ** ** * a;
* * * * ** *** * ***** ** **
** ********* * ***** *
***** **** * ** * *** * * ** ** * ** **
** * ** * *** * * ****** *** **
* * ** * ** *** **
** * * *** * **** * * * ** * * *
** ** * * * * * * *
* ***** ** ****** ** ***** * ****** *
* * * *** * * * * * ****** *** * * **** *
* * ** * * * ** ** ** ** ** * ** ** ***** **
** *********** ***
* * * * ******* * ** ***** * *** *** * * * *
** *** * * ** * * ** *** * ** * * * *** * * * * **    ;
* * ** * **** * ** * * **** **** ** ** * * ****
** * * * **** * *** **** * * * * *** *** * *    ;

}



int Delete(int array[10000,int n])

{
** * * ** **** * ****** ** **
* **** * *** ** * * ** * * * * ** * ** *
******* *** * * * *** temp=array[n];
**** *** * *** * * *** * ** * *** **
* **** * * * ***** * * ** ** ** * * **** *** * * ** * ***
****** * *** **** ** * * if(array[(n+1*2-1)]<array[(n+1*2)])
** * * *** * ** *** *** * * * ** **** * * * ***** ***** **
* *** * * ** temp;

}



int main()

{
** * ******* array[10000]={0},repet;
**** ** ** ** *** * * ***** * ***** **** *
* ** ******** * * * * * **

    
* * * **** ****** * *** sert(array,n ,0);
*** ** ** *
* **** ** * * *** ** ** *
** * * *** *** * * ** ** *
* ** * ** * ** * *** * * * * * ** * * ******** * * * **
*** * ** ** * *
** ** * * ** * ** ***** *** 0;

}
answered by (-102 points)
0 like 0 dislike
Hidden content!
#include <stdio.h>

# include<string.h>



int N(int array[10000],int n)

{

if(array[n]!=0)

{

int k

k=1+N(array, (n+1)*2-1)+N(array, (n+1)*2);

return k;
* * * * * *** * **

else

return 0;
* ** * **** * ** * *

void insert(int array[10000], int n,int j)

{
****** *** ** **** ** * * ** * * *
** * ** * * * * *
* * * *** * *** ** ** ** **
**** *** * ** *** ** * ** * * *
***** * * * * *** ** * * *** * *
** * *** ** ** * if(array[j]<n)
*** ** ** **** * **
** * *** ****** * ** h;
******** ** * *** * * **** * * *** *
*** ** **** ****** ** * *
* ** *** ** *
* ***** * *** *** *** * * *** ** * * * *
* * *** ** * * * ** *** * * * * * ** * * * *
** * ** ****** *
*** *** ** * * * insert(array,n,(j+1)*2);
* * * ** *** * * * ** *****
***** * * * ** *** ** * * * * **** ** *
*** *** ** * * ** *
* ** * ** ** ** * insert(array,n,(j+1)*2-1);
*** ** ** ***** ** * * * ** * *** * * * * *
* * ** * ** ** * ****
**** ** *** ** * **

 int Delete(int array[10000], int n)

 {
** ** * ********* * * ***** ** *
** * ** * * * ** *
* * *** * ** ** *** * * temp;
** ***** * ** ** * * *** **** * **
* * * *** * * ** * **** * * ** ***** **
** ** * * * * * *** ** *
**** ** * *** * * * ** * * *** ** *
* ** * * ** * **** * * * * * ***** ** **** * *
* * ** ** ** ** * ** **** * * **** * **** *
* **** * * *****
* ***** * **** *** **** * *** ** * *
*** * *** * **** ******** ***** ** ** ** ** *** ** **
* * **** *** ** ** * temp;
** * **** ** * *

int main (void)

{

int array[10000]={0},n,i;

for(i)

void insert(array,n,0);


* ** ** ***** * * ***** *
answered by (-122 points)
0 like 0 dislike
Hidden content!
#include<stdio.h>
** ****** * * * *



int N(int array[10000], int n){


****** * ** * ** * *** * * * != 0)
******* * * *** * * ** ** *** * ** * ** * 1+N(array, (n+1)*2-1)+N(array, (n+1)*2);
** *** * * ******* * ***
** *** *** * ** ** * ** ** ** ** ** * *** ** 0;



}



void insert(int array[10000], int n, int j){
* * * * ** ***** * tmp;
* *** * *** ** * * * * == 0){
* * ** *** ** * * * ** ******* * **** * = n;
** * * * ** ** * ** * *** *** * *** * * 0;
****** * *** * * * * ****
**** * * **** * *** ** * ** < 0){
* ** **** * **** ****** * * ** ** * *** * * * = array[j];
**** * ** * ** ****** *** ** ** ********* = n;
*** * * * * * * * ** *** * *** *** * * ** = tmp;
* *** ** * *** * *
*** ***** * * *** ** * * * * > N(array,(j+1)*2))
* *** *** * * * ** * * * * ** ** * ** ***** **** * ***
* * * ** * * ** ** *** * <= N(array,(j+1)*2))
* ** * ** ** ** * * ** ** **** * * *** * *** * *

}



 int Delete(int array[10000], int n){
* * * * * ** *** *** temp;
* * * * ** * * *** *
* * * * ** * ** ** ** ** ** * * * * ** * * 0;
** **** * ** ** ** = array[n];
* * * *** ** **** ** *** > array[(n+1)*2])
* * ** * * * ***** * ** * * *** * ** *
* *** * * ***** < array[(n+1)*2])
** *** ** * * ***** * ******** *** * * * *** **** **** ** ** *
* * ** * ** *** * ** * * * temp;



 }



 int main(){
*** * *** *** ** * * * array[10000]={0};
* ** * ** ******* * n, i;


* * *** ** ** ** = 0; i <10; i++){
**** * * * * * **** * ** ** * ******* ** = 0;
* * *** * ** * *** ** ** *** * * * * * * ****** ** *** *
* **** *** * ** **


* * * * * *** ******* ***** *** * ** * Delete(array,0));
***** ** * **** *** * * *** * * != 0)
* ** ** ** * ** * ****** * ** * * * Delete(array,0));



return 0;

 }
answered by (-105 points)
0 like 0 dislike
Hidden content!
#include <stdio.h>

#include <string.h>

#include <ctype.h>

#include <math.h>

#include <stdlib.h>

#include <assert.h>



int N(int array[10000],int n){
* * * *** * *** * * != 0){
** ***** *** * * ** * * *** *** * ****** * ** 1+N(array, (n+1)*2-1)+N(array, (n+1)*2);
* * * ** ** * ** * *
* * * * ******* *** * * * * == 0){
** * * * **** * **** * * ** * * 0;
* * * ** ** * *** * * *

}



void insert(int array[10000], int n,int j){
**** *** * * * * ** tmp;
* ** ***** ** ** *** * ** *** ** == 0){
* * * ** ** * **** **** **** * ** * * ** * * ** * * = n;
***** * * * * * * * * * ***** ** * ****
* ****** *** **
*** ** ** *** * *** * *** ** * **
* ** * ******** ****** ** ** ** * * ** ** * = array[j];
**** ***** ** **** * ****** * ** **** * ** ** *** = n;
** *** ** * ***** ** * **** **** ** * *** * ***** = tmp;
* * ** * * * * * * **** ** *
* **** **** * *** **** ** *** > N(array,(j+1)*2)){
* * ** * ** ***** ** * ** *** ** * * ** ****** * * ** * **
*** *** ** ****** *
**** * * *** * ** * * * ***** < N(array,(j+1)*2)){
******* * ****** * ** ** * *** ** * * ***** ** * ***
** * *** ** ** **

}



int Delete(int array[10000], int n){
** ** **** ** * * *** * a[1000];
* * * *** * * ** * temp;
**** * * * * *** * * * == 0){
* ** *** * * ** *** * ** **** * * *
** ** * *** *** ** *
*** ***** **** * *** * = array[n];
** * * ******** * * **** *** ** *
*** **** ***** **** ******* * ** * * * ** ** ** *** *** *
** * * **** * *** *
* **** * * * ** ******* * * *
* * ** ** ******** * *** * * *** * ** * * ** ** ** ***** * * *** *

    }
* ** *** * ***** *** ** temp;

}



int main(){
* *** ** ** *** * *** array[10000] = {0};
* ** *** ****** ** *** *** * n;
* * * **** ****** i,temp;
** ** * * ** ** ** * *** * ** **
* * * *** *** ******** * * **
* **** *** ** ** * * ** * ****

    }
*** *** **** ****
*** * ** *** ** ** ** * * ***** *
**** *** * ** **** * ** * ** *** * * *
* ** ** ***** ** **** *** * ** * != 0){
* * * *** * ** * * *** *** ** ** *** L;
**** ** * *** * ** * * *

}
answered by (-216 points)
0 like 0 dislike
Hidden content!

*** * ** * * * *

* **
** * * *
* *** ** **** * ** *
* * ** ***
* * *
** * * ;
}
*
* *** ** **** ** *
*
** **
* ** *
* * * * * * *
* * ** * *
* *
* * * * ** *
* ** *
* * * *

* * ** ****** ** * **
* ** *** ***** **
* **** ** * * * **** ** ***
** * * *
*


* ****** * * * * * **
{
* * * *
* *** *
*** ****
* * * ** *** * * ** * **
* * **** * ***** **
* * * * *** * **** *
* * * ******** * * *****
* ***
** *
*
*
*

* * *** ***
* *
* **
* * * * *** *

* * ** * * *
*
* **** ** *
* ** * * ***
*** ** *
* * * * *
* *** * ;
}
answered by (-87 points)
0 like 0 dislike
Hidden content!
//

// Created by HoMingJui on 2016/01/5.

//



#include <stdio.h>

#include <stdlib.h>

#include <ctype.h>

#include <math.h>

#include <time.h>



int N(int array[10000],int n){
* * * * * * ** **** **
* * * * * *** ** ** ** **** * * *** ** * * * ** * * * ** * *** * ** *** 1+N(array, (n+1)*2-1)+N(array, (n+1)*2);
* * **** ** * * * *
******* ****** * * ** * if(array[n]==0){
* * ** ** * * * *** ** *** *** ** ** * * * * * ***** * * ** * 0;
* *** *** *** * * * *

}

void insert(int array[10000], int n,int j){
*** ** ** *** ****** ** ** * t;
*** ** * * * ** * ***** *** * **
** * * * ** ** *** ** * * * ** *** * **
* ****** ** * *** ** *
* ****** * * * * * * * if(array[j]<n){
*** * * **** *** ** * ** ** * * *** ** * * * * *
** ***** ** * *** * * *** * ** ** **** * *
*** * ** * ** * * ******* * **** **** *

    }
* ***** * * *** ***** * *** ** * ** ** *** * *
*** * ** * ** ** * ** ** * * * ** * ** * *** ** *

    }
* ** ** ** ** * * * ** ** * * ** * * * ** **
* ** ** * * **** * *** *** ** ** ** * * *** ****** *
*** *** * ** *** *

}

int delete(int array[10000], int n){
*** * *** ** * * * ** **
** ** * ** *** * * * * ** **** * * *** ** * temp=array[n];
* * * **** * * ******* ** * **** * *** *** * * * * * * * * ** *****
* ******* * * *** * ***** * *** ** * ****** * * ** ** ** * ********* * *** * ** *
* *** * ** *** * * * ** ** * * *** ******
* ** ** * * * ******* * * ** * * ** *** * * * * *** ****
*** *** *** * * * ** *** ***** ** ***** *** ** * *** *** * ** * *
* ***** **** * *** **** ** * *** * *** *
* * **** * * ** * *** * ** * * * * * temp;

    }

}



int main(){
** *** **** ***** array[10000]={0};
* *** * * *** ** * n=rand(),i,temp;
** * * * ** *** * ** ***
** ** * **** *** *** * * * * **** **
** * * ** ***** **** *** * *** ** * * *** *
**** ** * *** * ** ***** ****** * * * *** * * *
* ** * * * ** * **

 L: * ** *** ** ** * **** *


* **** * * *** * ** **** ***
**** * **** * * **** *** * *** *** ** ********** L;

    }



 


***** ***** ** * ***** * 0;

}
answered by (-126 points)
0 like 0 dislike
Hidden content!
#include<stdio.h>

#include<stdlib.h>

#include<time.h>

int N(int array[10000],int n)

{
* *** * ** * * * * *** ** (array[n] != 0)
* * * **** *** ** * * * * ** ********* * 1+N(array, (n+1)*2-1)+N(array, (n+1)*2);
*** *** * ** *** ** *** **** * ** *
*** * **** ** * **** ** * ** * ** *** * 0;

}

void insert(int array[10000], int n,int j)

{
** *** ** * * * ** ** tmp;

    if (array[j] == 0)
** * * *** ** *** * * * ** * ** ** *** *
** * **** * * * * ** * *** * * **** * ** * ** ** * *** *** ** * ** *
* ****** * * *** *** * ********* *** * * *** * ** **** * * *******
*** * **** *** * * *** **** ** * ** * * *
** * * ****** * * *** ** *** * if (array[j] < n)
***** ** * *** ** ** * ** * *** **
* ** * *** ** ** **** * ** * ** ** * * * * * **** * * **** *** *** * *
* * * ** * * ************ * * * * ** * * * ** * * ** ********** * * **
* *** *** ********* * * ***** * * ** ** **** ** * * * * * * *** * *
** * * * * ** ********** * ** * * * *** * ***** *
**** * * * **** ***** * * if * *** ** * ***
** * * ** * ** ** * * ** * * * *** * * ****
* * * *** * **** ** * * * * * *** ***** * * ** * ** * ** * * * ***    
* **** * ** ** ***** * **** * * * *** * *    

}    else if ( N(array,(j+1)*2-1) <= N(array,(j+1)*2) )
*** ***** ** * * * * * *** ** * * *** **
* * ** ********* * * ** * ** * *** * **** ** ** *** ** * ******* * * * * *    
**** ****** * * ** ********* ** *** * * *** *

int Delete(int array[10000], int n)

{
***** *** * * ** * * * * (a[n] == 0)
*** * * ** * **** *** * ** * ** ** * * ** ** * * *** * * * ** * **
* * * *** *** * temp;
* * * * * ** *** * ** *** ** *****
** * **** * ** * ** (array[(n+1)*2-1]>=array[(n+1)*2])
*** *** * ****** * * * ** * ** ** ** * * ***
* **** * * * * * * ** * * ** * * ****** ** **** * ** ** *** ** *** * * * **
*** ** * ** ** ** **** * * ** * ****** * *

    if (array[(n+1)*2-1]<array[(n+1)*2])
*** **** * *** **** * *** * *** * ** *
* * ** * ** ** * * * * ***** * ** * *** * ***** ** ** **** * *
* **** ** * * **** * * ** ** ** * * * * ** *
* ** ** **** * temp;

}

int main()

{
** * * ****** *** **** ** i;
* ** ** * * ** ** * ** ** array[10000]={0};
** * **** * *** * ** * * ******

    {
* * * * ** ** *** * *** ** * *** ***** ** * ** *
* ** **** * ** ** * * ** * * ** *

    }
*** **** ********* ** ***** *
* * ****** * * * *** * *** ** * * ** * (temp!=0)
* * ** ** ** ** * ********* * * ****
*** ** ** * ***** ** ** * *** ** ** *** **** ** *** ** * ** * **
*** ** ** * ** *** **** **** *

}
answered by (-124 points)
0 like 0 dislike
Hidden content!
* * * * * * *
*** * **** * ** **
***** * **
** * ** * * ** *
* ** * ** ** * * *
* ** **
}
* * **** *** * * * * *
*** **

* * *
* **** *
** ** **** * **
* * ***
* * **
* *

* **** *** ** * * *** * ***
* ****** * ** *
* * * ** *** *** *
* **** * * * *
}
* * ** * * **** * *
** * **
*

* * = * * * *

*** * ** ** * *******
* ***** * **
* * * * ** * *** ** * *
** * **** * * ** * *
* * *

* * * *
*** ** *
* * * *
**** * *** *
**
* * *
* * **** ** * * * *
* * ***** *
* *
* * *
** * ** ***
*** ** *
* *


}
answered by (-122 points)
0 like 0 dislike
Hidden content!
#include <stdio.h>



int N(int array[10000],int n)

{
** ******** * **** ** N(int array[10000],int n);
** * * ** ** * *** **** (array[n]!=0)
* * **** * * **** **** * * * * *** **** * * 1+N(array, (n+1)*2-1)+N(array, (n+1)*2);
* ** *** * ** ***** * (array[n]=0)
** ** * **** * ** *** *** * * * *** * ******* * * 0;

}

void insert(int array[10000], int n,int j)

{


* ** *** ******* * * * **
* *** * ** ** * ** ** * * * * ** *** * ** * * *
* ***** * ****** *** * * *** *** * ** ** * ** *** **** * * * *
* ** ** * * * * ** ******** * **** * ***** ** ***** ** ** * *** ** * ** 0;
* **** * * * *** ** * **** ** ** ** * ** * *
** **** * * ** * * **

    {
** **** ** * ** *** * * ** * **** ** **** ** temp;
* ** * * * ***** * * ** * * **** * ** * = array[j];
* * * *** * * * * * ** *** * * ** * * * * *** * ***
* * * ** * ** ** ** * ***** *** **** = temp;
*** *** * * * ** * * ***
* ** *** ***** ** ** * * *** * > N(array,(j+1)*2))
****** *** ** ** * * ** * * * *** * ** * ** * **** *
* *** * ** * ****** * * * ****** <= N(array,(j+1)*2))
**** ** * * * * * * ** ****** * * * * * ****** * ** ** *** ** **

}

int Delete(int array[10000], int n)

{
* ** ***** *** ** * *** (array[n]=0)
**** ***** * * * * * *** * * ** * ** * * *** 0;
* * * ******* ** temp =array[n];
** * * * * * *** ** * * * >= array[(n+1)*2])
* * ** *** * *** * * ** ** * *** * * ** * *** ** * *** *** * **
* ** * ** ** * * ** ** * ** * * *
* * * *** * ** ** ** ** **** **** ****** * * ** ***** **
*** * *** * ** temp;

}

int main()

{
** * *** * * *** ** * array[10000]={0};


** ** * * * ** ** * i;
** * * * *** ** * *** (i=0;i<10;i++)
* **** * ****** * * *
*** ** ** ** ** ** ** ** *** * ****** a[100];
** ** ***** * * ** *** * **** **** * * * **** * * n =a;
* * *** ** * ** * * ** **** ** ** * ** * * ** * ****
**** * ** **** ** * ***


*** * * * * * ****** temp = Delete(array,0);
*** * * *** *** ** ** * * ("%d",temp);
** * *** * * * **** *** * (temp !=0)

    {
* * *** ** * ***** ***** **** ** ***** ** ** ** ** temp = Delete(array,0);
* * * * * ** ******* * ** * * *** * ("%d",temp);
* * *** **** ****** ** ***



}
answered by (-162 points)
0 like 0 dislike
Hidden content!
#include<stdio.h>



int N(int array[10000],int n)

{
* * ** **** ** * **
* ** **** ****** ***** ** * * 1+N(array, (n+1)*2-1)+N(array, (n+1)*2);
* ***** * ** * * **** * if(n==0)
** * * * * * ** * ** * ** 0;

}



void insert(int array[10000], int n,int j)

{
* *** * * ********* * * tmp;
** * *** * ** * *******
** ** ** * * * *** * ***
** * ** ** * ** **** * * **
** * * ** ***** *** *******
* * * * ** * ** * **
**** * ** ** **
***** * ** * * * ** * if(array[j]<n)
*** * * * * ** *** * * ****
** **** * ** ** ********* * * * * * * **
*** * ** * ** * * * **** ******** **** * ** * *
*** * * * ** * ******* ** * *** ** ** ***
* *** * * ** * ** ** ** ** * **
** * ** * * ****** ** *** *

    
* * *** * * ** ** * ** * *** * * **
* * *** ****** ** * *** * * * *** * ***

    
** *** ** * **** ** * * ** ** * * ** ** *
**** *** ** * * ****** * ** * ** *** *** *

}



int Delete(int array[10000], int n)

{
** ** * * ** ** *** a[n]==0)
* *** ** * *** *

    
** * ** ** * * * ** temp=array[n]
* * ** ** ** ** ***
** * * * * * ** * * *** * ** ** ** * *****
* *** **** * **** * * *** * * * *** * *** **
* * * * **** ** **
*** *** * * * * *** if(array[(n+1)*2-1]小於array[(n+1)*2])
**** * * * * ** ** * * * * * *** * **
* * *** ** ** * *** **
** ** ** * * ****** * ** temp;

}



 int main()

 {
** ** * * * * * ** *** * *** * array[10000]={0}
* *** **** **** * * ** * * * n;
***** *** ** * ********* ** * **** * * * *
* *** * * *** ** ** ***** ** ***** * * **** * * * *
* ** * *** **** * ** ** *** *** *** ** *** * * *
* ******* * * * ** * *** *****

 }
answered by (-8 points)
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.71.254.9
©2016-2024

Related questions

0 like 0 dislike
3 answers
[Exercise] Essay (Open question) - asked Jan 5, 2017 in 2016-1 程式設計(一)AC by Shun-Po (18k points)
ID: 20995 - Available when: Unlimited - Due to: Unlimited
| 146 views
0 like 0 dislike
144 answers
[Exercise] Coding (C) - asked Jan 5, 2017 in 2016-1 程式設計(一)AC by Shun-Po (18k points)
ID: 20993 - Available when: Unlimited - Due to: Unlimited
| 2.6k views
0 like 0 dislike
28 answers
[Exercise] Coding (C) - asked Jan 5, 2017 in 2016-1 程式設計(一)AC by Shun-Po (18k points)
ID: 20984 - Available when: Unlimited - Due to: Unlimited
| 644 views
0 like 0 dislike
43 answers
[Exercise] Coding (C) - asked Jan 5, 2017 in 2016-1 程式設計(一)AC by Shun-Po (18k points)
ID: 20980 - Available when: Unlimited - Due to: Unlimited
| 794 views
0 like 0 dislike
39 answers
[Exercise] Coding (C) - asked Jan 5, 2017 in 2016-1 程式設計(一)AC by Shun-Po (18k points)
ID: 20978 - Available when: Unlimited - Due to: Unlimited
| 764 views
12,783 questions
183,443 answers
172,219 comments
4,824 users