1. Modify the following code as needed to run in your environment. As well as th
ID: 3755924 • Letter: 1
Question
1. Modify the following code as needed to run in your environment. As well as the values for M and N given in the code, test all combinations of values of M = 2, 3, 5, 10 and N = 103, 104, 105, 106.
2. Explain the “node” class and the “main” function through comments in the code file and a written summary that includes your displayed test results.
3. Create the following functions for processing nodes: remove(), insert(), next(), annd item(). Test them independently of the processing done in the code below. Be sure to document your code, summarize the way you implemented them, and how you tested the functions.
4. Replace any operations in the code below with equivalent functions that you implemented in problem 3 above, where appropriate. Document your replacements and give proof in your summary that you get the same results as with the original code.
#include <iostream>
using namespace std;
class node
{
public:
int item; node* next;
node(int x, node* t)
{ item = x; next = t; }
};
typedef node *link;
int main()
{ int i, N = 9, M = 5;
link t = new node(1, 0); t->next = t;
link x = t;
for (i = 2; i <= N; i++)
x = (x->next = new node(i, t));
while (x != x->next)
{
for (i = 1; i < M; i++) x = x->next;
x->next = x->next->next;
}
cout << x->item << endl;
}
Explanation / Answer
No significant changes were measured as average time comes out be almost same i.e., 47ms.
ANSWER 6
Average running time for int type array increased by 5ms while for bool type and char type array average running time remained the same.
int type dynamic array:
char type dynamic array:
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.