Академический Документы
Профессиональный Документы
Культура Документы
Data structure
A data structure is not a passive object: We also must consider the operations to be performed on it (and the algorithms used for these operations). The data structures that we consider in this chapter are important building blocks that we can use in a natural manner in C++ and many other programming languages.
Characters (chars)
Type-dependent operations
Program 3-1
Program 3-2
interface
An example in C
/* in the file named Number.h */ typedef int Number; Number randNum(); /* in the file named int.c */ #include <stdlib.h> #include Number.h Number randNum() { return rand(); } /* in the file named avg.c */ #include <stdlib.h> #include <math.h> #include Number.h ...
pointer
A pointer is a reference to an object in memory (usually implemented as a machine address). We declare a variable a to be a pointer to (for example) an integer by writing int *a, and we can refer to the integer itself as *a. We can declare pointers to any type of data. The unary operator & gives the machine address of an object, and is useful for initializing pointers. For example, *&a is the same as a.
Chien-Yu Chen, BIME@NTU
Arrays
a[i]
Using pointers
Sieve of Eratosthenes
Eratosthenes (276~194 BC) . Eratosthenes (Sieve). , 100
2~100 2, 2 , 2 3, 3 , 3 5, 5 , 5 ..., , , 2,3,5,7,...,97 100
http://home.educities.edu.tw/kuen/maths/algorithm01.htm
Chien-Yu Chen, BIME@NTU