1) How would you implement 2-D arrays if C only had 1-D arrays? You can use 1-D
ID: 3540125 • Letter: 1
Question
1) How would you implement 2-D arrays if C only had 1-D arrays? You can use 1-D arrays to do this just like C does, so you will need to write some code that does this.2) write some code to operate on a doubly-linked list
3) write some code to operate on a singly-linked list
4) use a auxiliary data structure to help a program free dynamic memory that is allocated for use by a more complicated structure
5) how data values are stored in a square 2-D array. 1) How would you implement 2-D arrays if C only had 1-D arrays? You can use 1-D arrays to do this just like C does, so you will need to write some code that does this.
2) write some code to operate on a doubly-linked list
3) write some code to operate on a singly-linked list
4) use a auxiliary data structure to help a program free dynamic memory that is allocated for use by a more complicated structure
5) how data values are stored in a square 2-D array. 1) How would you implement 2-D arrays if C only had 1-D arrays? You can use 1-D arrays to do this just like C does, so you will need to write some code that does this.
2) write some code to operate on a doubly-linked list
3) write some code to operate on a singly-linked list
4) use a auxiliary data structure to help a program free dynamic memory that is allocated for use by a more complicated structure
5) how data values are stored in a square 2-D array.
Explanation / Answer
3>struct node
{
int data;
struct node *next;
}*head;
void append(int num)
{
struct node *temp,*right;
temp= (struct node *)malloc(sizeof(struct node));
temp->data=num;
right=(struct node *)head;
while(right->next != NULL)
right=right->next;
right->next =temp;
right=temp;
right->next=NULL;
} //singly linked list with append code
5>A static two-dimensional array looks like an array of arrays - it's just laid out contiguously in memory. Arrays are not the same thing as pointers, but because you can often use them pretty much interchangeably it can get confusing sometimes. The compiler keeps track properly, though, which makes everything line up nicely. You do have to be careful with static 2D arrays like you mention, since if you try to pass one to a function taking an int ** parameter, bad things are going to happen. Here's a quick example:
int array1[2][2] = {{0, 1}, {2, 3}};
In memory looks like this:
0 1 2 3
exactly the same as:
int array2[4] = { 0, 1, 2, 3 };
4> Auxilarry datastructures can be freed by using free(pointer); line.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.