$29
Read the following C code about implementing a sorted linked list in an array:
#include <iostream>
using namespace std;
struct node {
int num;
}; struct node* next;
int input[10] = {5, 10, 2, 4, 15, 22, 100, 99, 2, 10};
struct node A[ 10];
struct node *head = NULL;
int size = 0;
void insert (int a_num)
{ struct node *p = head, *p_prev = NULL;
}
A[size].num = a_num;
if (size == 0) {
head = (struct node *) A;
} A[0].next = NULL;
else {
while (p->num < a_num) {
p_prev = p;
p = p->next;
if (p == NULL)
break;
}
if (p_prev != NULL) {
p_prev ->next = (struct node *) &A[size];
} A[size].next = p;
else{
A[size].next = head;
} head = (struct node *) &A[size];
}
size++;
return;
int main()
{ int i = 0; struct node *p;
}
size = 0;
head = NULL;
while (i < 10) {
insert(input[i]);
} i++;
p = head;
while (p != NULL) {
cout << p->num << endl;
} p = p->next;
return 0;
1. A MIPS assembly code for this C code is provided with code for the insert function removed. Please add your code for this function at the place marked in the file, and run it in the SPIM simulator:
2. If your code does not run or produces result very different from correct one (the list of sorted numbers), your score would be substantially reduced. By adding comments, you may help grader to understand your program and lose fewer points.
3. Submit your source code (named “lab3.asm”) via the blackboard by the due time.
4. Start your work as early as possible.