Lecture_10_DynamicDataStructures.pdf
(
139 KB
)
Pobierz
Microsoft Word - Lecture_10_DynamicStructures.doc
LECTURE 10
Structures – multiple (compound) variables
Static and dynamic data structures
list, queue, stack, tree
Programs: c5_1.c, c5_2, c5_3, c5_4, c5_5
Tomasz Zieliński
VARIABLES HAVING COMPLEX STRUCTURE (1)
Simple variables:
char, short, int, long, float, double
(unsigned) char, short, int, long
Examples:
char
c, s[10];
int
i, j, k, l, m[3][3], n[5][5][5];
float
x, y, z
c = getchar();
strcpy(s, ”Smith”);
i = 10; j = 20;
k = i+j; l = i*j;
m[0][1] = 1;
n[0][1][2] = m[1][2] + 128;
VARIABLES HAVING COMPLEX STRUCTURE (2)
Multiple (compound) variables = structures
Example:
struct
person
{ <------- variable type
person
char
surname
[20];
char
name
[10];
int
age
;
int
height
;
}
student
; <------- declaration of variable
student
of type
person
strcpy(
student
.
surname
, ”Smith” );
// initialization of
strcpy(
student
.
name
, ”John” );
// a multiple variable
student
.
age = 23; // (its sub-variables)
student
.
height = 187; //
struct person
patient, student
= {”Smith”, ”John”, 23, 187};
VARIABLES HAVING COMPLEX STRUCTURE (3)
Example:
struct
person
{
<---------- variable type
person
char
surname
[20];
char
name
[10];
int
age
;
int
height
;
}
*
pstudent
;
<--------- declaration of pointer to variable
student
WRITING CONVENTION: *xxx.yyy = xxx->yyy
strcpy(
pstudent->
surname
, ”Smith” );
// initialization of sub-variables
strcpy(
pstudent->
name
, ”John” );
//
pstudent->
age = 23; //
pstudent->
height = 187; //
struct osoba
*
ppatient, *pstudent
= {”Smith”, ”John”, 23, 187};
DATA STUCTURES (1) –
static and dynamic
List
:
of computer users, excursion participants, students,
patients, ...
Queue
:
documents waiting for printing by a network printer
Stack
:
of stored data with information concerning interrupted
programs, waiting for execution (processor time)
Tree
:
of directories on a computer hard disc
Static:
a table consisting of many elements of the same type,
often not fully filled with data,
sometimes pack-full (overloaded)
Dynamic:
chain of nodes (block of memory cells) that are
pointed out to each other
Plik z chomika:
bennett
Inne pliki z tego folderu:
Symfonia C++ Tom 1, 2, 3, 4.jpg
(14 KB)
Lab_06-Instrukcje-sterujace.pdf
(197 KB)
Lab_05-Obliczenia-w-C.pdf
(299 KB)
Rules_2011_I_pl.pdf
(39 KB)
Wyklad_13_Grafika_C.pdf
(923 KB)
Inne foldery tego chomika:
Circuit theory
Cywilizacja Konfucjańska
Historia Chin
Historia Filozofii
IT
Zgłoś jeśli
naruszono regulamin