0 like 0 dislike
409 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 | 409 views

16 Answers

0 like 0 dislike
Hidden content!
*** ** * * ** *



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 )

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

}



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

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

}



int main()

{
**** **** **** ** ** ** * * x;
* * ** * * * ** ** * * array[10000]={0};
*** **** **** ***** = 1;x <= 10;x++)
* *** * * ** **** ***
*** * * ** * ** ****** ** ***** ** * int n;
* ** ** ** ** * * * * *** ** * * *** * * *
** * ** * *** * * *
* * * *** * *** ******** = delete(array,0);
**** * * ** ** * ** ****** ** * ** ** *
* ** ****** **** * ** != 0)
** * *** * ** * *** ** * *** **** ******** * * temp;

}
answered by (-320 points)
0 like 0 dislike
Hidden content!
***
* * *
* **
*
* * * * ** ** *
**** ** *** * *** *
* * *** **
*** * * * *** ** * * * *
* *
* *
}
** * * * * ** * * *
{
* *
** *
** ***
* **** * ** *
*
** **** *
** *
* **
**
}
answered by (-248 points)
0 like 0 dislike
Hidden content!
* * * * ** * ***
* * ** * * ***

int main()

{

int N(int array[10000],int n)
* ***** ** ** * ***
**** * ** ** * * * ******* * * ******** **
* * * * ** * ** * *** *** * * * * ** *** ** ** ** * *** ** * 1+N(array, *** *** * (n+1)*2);
** * *** ** ** * ** ** ** * * * ** ** *

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

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

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

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

* **
* * *
*

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


}
* * ** ** * *
{
* *
***** **
* *
* **
* * * ** **** * ** *
* *** ** * ** **
** *** **** * * * * *
* * * *** * * ** *
* **



** * *

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

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

#include <stdlib.h>

#include <string.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){
***** * * **** * * **
*** *** * ** *** * * * * * v;
** ** * * ** * * *
** * * ** * ** ** ** *** (array[j] == 0)
** *** *** ***** * * *** *
*** * * ** **** **** *

    
* *** ** ** * * if (array[j] < n)
** ** ** *** * ** ** **
* *** * * *** *
******* *** ** * * ** * * * * ********* **
**** * ** *** ** * * ** ** ** * **** * * = array[j];
* * * ** ** ** * ** * * * **** *******
** **** * **** * * * * ***** ***** * * * * * = n;
* **** *** **** * * * * ** *** ** * ** *
***** * * **** * *** ** *** ** * ** * **** = v;
* * * **** * ** **** ** ** ***** * ** * *
*** *** ****** * ***** *
***** ** * * * * * ***
** ** * * ***** **** ** * if (N(array,(j+1)*2-1) > N(array,(j+1)*2))
* ** ** * * ** *
****** **** * **** **
** *** * * ** *** *** * ** * *** * **
* *** **** * * * ** *** * *** ** *
** *** ** *** ** * *** * * ** **
* * * ** * ****
* ** * * ** ***** ** *
* * *** * * * ** * *** if (N(array,(j+1)*2-1) <= N(array,(j+1)*2))
* * * ** *** * *** * *
**** ** * * ** * ** ***** * **** ** ** ** * * * *
* *** * *** ** **

}



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

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



{
* ** * ** ** *** **
*** ** ** ** * ** (array[(n+1)*2-1] >= array[(n+1)*2]){

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

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

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

}



int main(void){

    
** **** * * *** ***** * array[10000]={0},n,i,temp;
* ** ***** * * ** *** * *
* * * ** * *** * * * * * (i = 0;i <= 9;i++){
* ** *** * * * * **** * ********* ** * ** * * **
**** ** * *** *** * *** ** ** * ** * * * * *** ** **** **
** *** * *** ****** ** **** *** * * * *** * ** * * *
* *** *** ****** * *** * * *
* * * ******
* ** ** * ** ** * ** *** != 0){
* ** * ** ** ** * *** *
** * *** ** ** **** * ** * *** *

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

} ** * ** ** ** *** ****** * * * *****
* *** * * * * * * ** * *
** * ** ** * * * *** * * 0;
* *** ****** *** ***

}
answered by (-157 points)
0 like 0 dislike
Hidden content!
#include <iostream>

#include <algorithm>

#include <cstdio>

using namespace std;

class Time

{

public:
* * * * ** * * * * * * * * hour;
* * * ** * * * ** * minute;
* ****** ******** *** ** *
******* * * * * * ** * *
*** **** ** * **** ** ** ** * **** * *** = 0;
*** * * ** * * *** * **** ** ***** * = 0;

    }
* ** *** * * * ******** set_time(int h,int m)
*** *** ** * ** *** * *
** * *** *** ** * ** ** ****** **** * * = h;
*** ** ****** ** * *** ** * ** ** * * * * *** = m;
*** *** * *** * *** * *

};

Time t[3];

bool cmp(Time a,Time b)

{
* ** * * * ** ***** *** *
* * * ** * * ***** * *
* * * ** * ** ** * * * ** * * *** ** ***** true;
****** ******* *** ****** **
** ** *** * *** if(a.minute>b.minute)
* * ** **** * * *
***** * ** **** * ** * * * ** * *** ** * * true;
* * * * ** *** *
** **** * * ** *
* * * * * ** *** * * * * * * * * *** * false;

}



int main()

{


* * * ** * ** ** * **** * h,m;
********** ****** ** ** * *** * c1=0;c1<3;c1++)
* * ** ** * * **** *
* ** ** ** ** ***** ** **** * * ********* * ** * **** * ***** * *** *
** *** ******* * * **** * * * * *** ** * * * ******* ** ** *
* ** ** **** ** * ** * *


** * **** * * ** * ***** * ** *
*** ** * **** *** ** ** ** * now:t)
* * ** ** *** ** * ***
**** *** * * * ** ** ** ** *** * ** * ** * * * ",now.hour,now.minute);
* * * ** ** * ** *** ** *** *
*** ** ** **** **** ** 0;

}
answered by (48 points)
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.70.131.69
©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
| 160 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
| 3.1k 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
| 694 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
| 935 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
| 884 views
12,783 questions
183,443 answers
172,219 comments
4,824 users