Find Jobs
Hire Freelancers

Heap Ordered Array

$10-20 USD

완료함
게시됨 4년 이상 전

$10-20 USD

제출할때 지불됩니다
Write a function, ValidHeap(), to test is an array conforms heap ordered binary tree. This function returns true is the array is heap ordered, false if not. Examples: Given A= [33, 65, 55, 64, 37, 25, 33, 34, 87, 0, 48, 95], ValidHeap(A,7) returns true since all parent nodes conform k >= 2k and k>=2k+1 rules for 7 items, that are from A[1] to A[8] ValidHeap(A,9) returns false since k=4 fails k >= 2k test (A[4] < A[8]) Make sure that the ValidHeap function has these parameters: array and size of heap-ordered tree. As you notice, the array size is not a parameter. Note that for binary heap trees, the first item, A[0], does not have any meaning for the tree structure, which may be ignored or used for some other purposes In your program, ask the user to enter a number between 0 - 11, and show return value of ValidHeap() for A= [33, 65, 55, 64, 37, 25, 33, 34, 87, 0, 48, 95]. PS: For this assignment, You may just expand the below existing code with your new function since it has already sink / swim-up functions. // Binary Heap Tree for Priority Queue #include <iostream> #include <stdio.h> #include <string> #include <stdlib.h> #include <iomanip> // std::setw // #define N 10 using namespace std; class BinaryHeap { public: BinaryHeap(); // Construction bool less(int i, int j); void exch(int i, int j); void swim(int k); void sink(int k); bool isEmpty(); int size(); void insert(int v); int delMax(); void ListArray(); void printT(int x, int id); private: int N = 0; int *pq; int capacity = 100; }; // Initialize the class BinaryHeap::BinaryHeap() { pq = new int[capacity]; cout << "A new priority queue with " << capacity << " capacity was created...!" << endl ; } void BinaryHeap::ListArray() { for (int i=1; i <= N; i++) // Remember we have "size" items { cout << pq[i] << ", "; } } void BinaryHeap::swim(int k) { while (k > 1 && less(k/2, k)) { exch(k/2, k); k = k/2; } } bool BinaryHeap::isEmpty() { return N == 0; } int BinaryHeap::size() { return N; } void BinaryHeap::insert(int v) { pq[++N] = v; swim(N); } int BinaryHeap::delMax() { int max = pq[1]; exch(1, N--); pq[N+1] = NULL; sink(1); return max; } void BinaryHeap::sink(int k) { while (2*k <= N) { int j = 2*k; if (j < N && less(j, j+1)) j++; if (!less(k, j)) break; exch(k, j); k = j; } } bool BinaryHeap::less(int i, int j) { if (pq[i] < pq[j]) return true; return false; } void BinaryHeap::exch(int i, int j) { int t = pq[i]; pq[i] = pq[j]; pq[j] = t; } //1-> 2, 3 //2-> 4, 5 //3-> 6, 7 void BinaryHeap::printT(int x, int id) { if (x>N) return; printT(2*x+1,id+10); cout << setw(id) << ' ' << pq[x] << endl; printT(2*x,id+10); } // The program lunches here int main( ) { BinaryHeap BH; for (int i=0; i < 20; i++) [login to view URL]( rand()%50 +1); [login to view URL](); cout<< " ------\n "; [login to view URL](1,10); }
프로젝트 ID: 22332683

프로젝트 정보

3 제안서
원격근무 프로젝트
활동 중 4년 전

돈을 좀 벌 생각이십니까?

프리랜서 입찰의 이점

예산 및 기간 설정
작업 결과에 대한 급여 수급
제안의 개요를 자세히 쓰세요
무료로 프로젝트에 신청하고 입찰할 수 있습니다
프로젝트를 수여된 사용자:
사용자 아바타
Hi I'm ready for the project. I'm an expert in Java & algorithms I read your specifications and I'm sure I can do it perfectly.
$20 USD 2일에
4.3 (60 건의 리뷰)
4.7
4.7
3 이 프로젝트에 프리랜서들의 평균 입찰은 $22 USD입니다.
사용자 아바타
I'm computer engineering TA with 10+ years of experience. Experienced with the data structures and advanced data structures types Experienced with BGI / DOS Programming / 80x96 program development and games development under DOS I'm experienced with the queues - stacks - linked list - trees - graph algorithms DFS - BFS - Dijkstra - primes's - heap - heap sort - binary heap - fibonacci heap I could help you making the full project working within few hours
$30 USD 1일에
5.0 (110 건의 리뷰)
5.7
5.7
사용자 아바타
I have been creating website and android app for almost 6 years I can even call my self a professional it's fun building a website I can create a wordpress website also I can create a real website Relevant Skills and Experience My Expertise Java, Javascript, Php, Html, Css
$15 USD 3일에
0.0 (0 건의 리뷰)
0.0
0.0

고객에 대한 정보

국기 (UNITED STATES)
GUILDERLAND, United States
4.9
7
결제 수단 확인
11월 26, 2018부터 회원입니다

고객 확인

감사합니다! 무료 크레딧을 신청할 수 있는 링크를 이메일로 보내드렸습니다.
이메일을 보내는 동안 문제가 발생했습니다. 다시 시도해 주세요.
등록 사용자 전체 등록 건수(일자리)
Freelancer ® is a registered Trademark of Freelancer Technology Pty Limited (ACN 142 189 759)
Copyright © 2024 Freelancer Technology Pty Limited (ACN 142 189 759)
미리 보기 화면을 준비 중...
위치 정보 관련 접근권이 허용되었습니다.
고객님의 로그인 세션이 만료되어, 자동으로 로그아웃 처리가 되었습니다. 다시 로그인하여 주십시오.