Design and Analysis of Algorithms 214.: Introduction To The C Programming Language
Design and Analysis of Algorithms 214.: Introduction To The C Programming Language
Design and Analysis of Algorithms 214.: Introduction To The C Programming Language
U.U.Samantha Rajapaksha
B.Sc.(Eng.)
Memory Layout
i a p
0 4 16 20
typedef struct
{
int number ;
char letter;
char name[10] ;
} any_name ;
any_name mystruct ;
int main( ) {
struct coordinates { coordinates c1;
unsigned char x; coordinates c2;
c1.x = 3;
unsigned char y; c1.y = 2;
unsigned char z; c1.z = 1;
}; c2.x = 0;
c2.y = 2;
c2.z = 3;
return 0;
}
c1 c2
struct coordinates {
unsigned char x;
unsigned char y; int main( ) {
unsigned char z;
}; new m1;
m1.position.x = 3;
struct new { return 0;
coordinates position;
char name[32]; }
int size;
};
struct S1 {
char c;
int i[2];
double v;
} *sp;
(Windows alignment)
c i[0] i[1] v
sp+0 sp+4 sp+8 sp+16 sp+24
MERGE(A, p, q, r)
1 n1 ← q - p + 1
2 n2 ← r - q
3 create arrays L[1.. n1 + 1] and R[1.. n2 + 1]
4 for i ← 1 to n1
5 do L[i] ← A[p + i - 1]
6 for j ← 1 to n2
7 do R[j] ← A[q + j]
8 L[n1 + 1] ← ∞
9 R[n2 + 1] ← ∞
10 i ← 1
11 j ← 1
12 for k ← p to r
13 do if L[i] ≤ R[j]
14 then A[k] ← L[i]
15 i←i+1
16 else A[k] ← R[j]
17 DAA 214 Lab 02 j←j+1
Sri Lanka Institute of Information Technology.