728x90
3Chapter 배열, 구조체, 포인터 - 연습문제
1. ④
해설 : 4 * 10 * 20 = 800
2. ④
해설 : 1000 + 4(float)*10 = 1040
3. ②
1) 40
2) 80
3) 40
4) 40
4.
int main() {
int two[10];
for (int i = 0; i < 10; i++) {
two[i] = pow(2, i);
printf("%d ", two[i]);
}
}
5.
struct person {
char name[10];
int age;
float wage;
}
6.
typedef complex {
float real;
float imaginary;
} complex;
complex c1, c2;
7.
typedef struct Complex {
int real;
int imag;
}Complex;
Complex complex_add(Complex a, Complex b) {
Complex c;
c.real = a.real + b.real;
c.imag = a.imag + b.imag;
return c;
}
8.
void insert(int array[], int loc, int value) {
for (int i = loc; i < n; i++) {
array[i+1] = array[i];
}
array[loc] = value;
items++;
}
9.
함수를 실행할때마다 n-loc 까지 요소가 밀리는 연산이 소요된다.
시간복잡도는 O(n)
10.
void delete(int array[], int loc) {
for (int i = loc; i < n; i++) {
array[i] = array[i + 1];
}
array[n-1] = NULL;
items--;
}
11.
위랑 똑같이 n번의 연산을 하므로 시간복잡도는 O(n) 이다.
12.
typedef struct test {
int x;
char s[20];
}test;
int main() {
test* p;
p = (test*)malloc(sizeof(test));
if (p == NULL) {
exit(1); //메모리부족
}
p->x = 100;
strcpy(p->s, "just testing");
}
728x90
'Major > Data Structure' 카테고리의 다른 글
[C로 배우는 쉬운 자료구조] 1장 개념정리 (0) | 2022.02.09 |
---|---|
[자료 구조] 최단 경로 - 다익스트라(Dijkstra) 알고리즘 개념 및 구현 * (0) | 2021.06.07 |
[자료 구조] 최소 신장 트리(MST) 개념 및 구현(Kruscal, Prim) (0) | 2021.06.03 |
[자료구조] 그래프 순회(Graph Traversal) 개념 및 구현 (0) | 2021.06.02 |
[자료구조] 그래프 개념 및 구현(인접 리스트) (0) | 2021.05.31 |