1 Data Structures Introduction - 1
1 Data Structures Introduction - 1
Scientific Calculations
1
Introduction
2
Introduction
3
Introduction
4
Introduction
10
Basic Data Types
11
Structured Data Types
14
Structured Data types: Classes: Graph Structure
15
Structured Data types: Classes: Cyclic Structures:
16
Structured Data Types : Arrays
An Arrays is a physically sequential, fixed size
collection of homogeneous objects.
In addition, objects with the structure have the random
access property.
I. The array is physically sequential in that the data objects
are stored in consecutive memory locations.
II. The array has a fixed size in that its size can neither be
increased nor reduced though the number of items it
contains can vary
III. The array is homogeneous in that they are made up of
objects that are all the same type.
IV. The random access property means that the time it takes
to access one object in the structure does not depend on
what object in the structure had been accessed
17
previously.
Arrays
18
Example 1: String Values in an array and Getting the greatest value in
the array
#include <stdio.h>
int main()
{
const int SIZE=5;
int numbers[SIZE]={3,12,5,2,10};
int i;
int greatest;
greatest=numbers[1];
for(i=0;i<SIZE;i++)
{
if(numbers[i]>greatest)
{
greatest=numbers[i];
}
}
printf("\nThe greatest number in the array is
%d\n",greatest);
} 19
Example 2: Getting Array Values from the user
#include <stdio.h>
int main()
{
const int SIZE=5;
int numbers[SIZE];
int j;
int num, sum;
printf("\nProvide Five Integers to be stored in the
array");
printf("\n___________________________________________
_______");
for(j=0;j<SIZE;j++)
{
printf("\nEnter Value %d:::",j+1);
scanf("%d",&num);
numbers[j]=num;
20
}
Example 2: Getting Array Values from the user
//program continued
//get the sum of the numbers
sum=0;
for(j=0;j<SIZE;j++)
{
sum=sum+numbers[j];
}
21
Multidimensional arrays
26
Assignment 1 (Due on or before 25th
July)
1) Write a program that does the following
i. Stores the following values in a 3 by 3 matrix
9, 3, 18, 5, 8 ,4, 17, 9, 17
ii. Outputs the sum of the values in each of the
rows of the matrix
Note: Assessment is by presentation of the
running program in a computer
27