For the following code:
#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;
}
$s0 = i
$s1 = 10
$s3 = head address
$s4 = size
$s5 = A address
How do I translate this into MIPS32 code? I think this is suppose to sort the linked list in array. I have a lot of hard time knowing how to translate this in to MIPS32. ANY HELP APPRECIATED!!!!
THANKS!!!!
THANKS!!!! THANKS!!!!
Comments
Post a Comment