Ask Question
30 September, 01:27

Write three functions in C/C++: one that declares a large array statically, one that declares the same large array on the stack, and one that creates the same large array from the heap. Call each of the subprograms a large number of times (at least 100,000) and output the time required by each. Explain the results. Explain why or why not you cant do this in Java, what are the implication of this? If you can't specify which type of array can you not declare.

+5
Answers (1)
  1. 30 September, 01:45
    0
    See explaination

    Explanation:

    #include

    #include

    #include / / std::make_heap, std::pop_heap, std::push_heap, std::sort_heap

    #include / / std::vector

    using namespace std;

    void StaticArray ()

    {

    unsigned int array[64536];

    for (unsigned int i=0; i<64536; i++)

    array[i]=i;

    }

    void Stack ()

    {

    stack mystack;

    for (unsigned int i=0; i<64536; i++)

    mystack. push (i);

    }

    void Heap ()

    {

    unsigned int myints[64536];

    for (unsigned int i=0; i<64536; i++)

    myints[i]=i;

    vector v (myints, myints+64535);

    make_heap (v. begin (), v. end ());

    push_heap (v. begin (), v. end ());

    }

    int main ()

    {

    StaticArray ();

    Stack ();

    Heap ();

    return 0;

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Write three functions in C/C++: one that declares a large array statically, one that declares the same large array on the stack, and one ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers