Skip to main content

Pertemuan ke1 - Array, Pointer, & Introduction to Data Structure - 2101629451 - Geraldus Tommy K.

ARRAY


Array is a kind of data structure that can store a fixed-size sequential collection of elements of the same type. An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type.

Multi-Dimensional Array


multidimensional array is an array containing one or more arrays. PHP understands multidimensional arrays that are two, three, four, five, or more levels deep.


*Theoratically no limit on how much dimension in an array. The only practical limits are memory size and compilers.

Sorting Array Values


int a[10] = { 3,4,7,6,5,1,2,8,10,9 };           //Array declaration size-10
	int n = 10;                                     //Temporary number for array size
	printf("\n\nArray Data : ");                    //Printing message
	for (int i = 0; i < n; i++)                     //Loop for displaying the data of array
	{
		printf(" %d ", a[i]);                   //Printing data
	}
	for (int i = 0; i < n; i++)                     //Loop for ascending ordering
	{
		for (int j = 0; j < n; j++)             //Loop for comparing other values
		{
			if (a[j] > a[i])                //Comparing other array elements
			{
				int tmp = a[i];         //Using temporary variable for storing last value
				a[i] = a[j];            //replacing value
				a[j] = tmp;             //storing last value
			}  
		}
	}


Pointer

Pointer is a data type whose value refers to another value stored 
elsewhere in computer memory using its address.

The two most important operators used with pointer type are:
&  the address operator
*   the dereferencing operator

If we have the declaration:
  int x;
 int *px;
then x is an integer and px is a pointer to an integer. If we say:
  px  = &x;
then &x returns the address of x and assigns it as the value of px.
To assign a value of x we can say
  x = 10;
or
  *pi = 10;

Data Strucutre


A data structure is an arrangement of data, either in the computer’s memory or on the disk storage.
Some common examples of data structures include:
Arrays
Linked lists
Queues
Stacks
Binary trees
Hash tables


Types of Data Structure


Arrays
A collection of similar data elements
Data elements have the same data type

Linked Lists
A very dynamic data structure in which the elements can be added to or deleted from anywhere at will
Each element is called a node

Queue
The element that was inserted first is the first one to be taken out
The elements in a queue are added at one end called the rear and removed from the other end called the front 

Stacks
Stacks can be represented as a linear array
Every stack has a variable TOP associated with it
LIFO (Last In First Out) / FILO (First In Last Out)

Binary Trees
A data structure which is defined as a collection of elements called the nodes
Every node contains a left pointer, a right pointer, and a data element

Abstract Data Type

        Abstract Data Type (ADT) is a data type that is organized in such a way that the specification of the objects and the specification of the operations on the objects is separated from the representation of the objects and the implementation of the operations.








Comments