Ask Question
20 December, 16:03

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.

+2
Answers (1)
  1. 20 December, 18:46
    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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers