Xmart Imaging【筆記試験】
1.sizeofを求める
2.大端小端:大端は低い住所から高い住所に書いて、直接写すだけでいい
3.単一チェーンテーブルの反転
#include <stdio.h>
#include <stdlib.h>
union my
{
int x;
int y[5];
char z;
};
struct you
{
int a;
union my b;
double c;
};
int main()
{
printf("%d %d
", sizeof(union my), sizeof(struct you));// 20 32
return 0;
}
2.大端小端:大端は低い住所から高い住所に書いて、直接写すだけでいい
3.単一チェーンテーブルの反転
struct node
{
int data;
struct node * next;
};
struct node * reverse(struct node * head)
{
struct node *p1, *p2, *p3;
if (head == NULL || head->next == NULL) return head;
p1 = head;
p2 = p1->next;
while (p2) {
p3 = p2->next;
p2->next = p1;
p1 = p2;
p2 = p3;
}
head->next = NULL;
head = p1;
return head;
}