110 likes | 295 Views
Data Structures. Ali Abdul Karem Habib Kufa University / mathematics & Science Of Computer. Data Structures. DATA STRUCTURE. SIMPLE. COMPOUND. LINEAR. NON-LINEAR. ARRAYS. LINKED LIST. TREES. STACKS. GRAPHS. QUEUES. DATA STRUCTURE.
E N D
Data Structures Ali Abdul KaremHabib Kufa University / mathematics & Science Of Computer
Data Structures DATA STRUCTURE SIMPLE COMPOUND LINEAR NON-LINEAR ARRAYS LINKED LIST TREES STACKS GRAPHS QUEUES
DATA STRUCTURE The logical and mathematical model of particular organization of data is called DATA STRUCTURE. Data Structures are containers for data. The simplest of them are called “atomic” because they hold only a single value and cannot be subdivided into lower-level components. Other “compound” data structures may hold multiple pieces of data, and are constructed from atomic types.
Simple Data Structure Arrays • The group of linked similar type of elements by one common name then it is called as array . • Its is the simplest type of data structure. • Array it is a container that holds a fixed length . • It is start at 0 0 1 2 3 4 5 6 7 8 9 20 Array length is 10
ARRAY .. Cont • Array Definition: int x[100]; char text[80]; • Array Initialization: int digits[5]={1,2,3,4,5}; char color[3]={‘R’, ‘E’, ‘D’}; • Multidimensional Arrays: int values[3][4]= { {1,2,3,4}, {5,6,7,8}, {9,10,11,12} } String: In C Strings are defined as arrays of characters.There are special string handling library routines like strcmp(s1,s2), strcpy(s1,s2),strlen(s)
Representation of array in memory • One Dimensional array • Location(X[I])=Base Address+(I-1) • E.g :- • Find X[4] , Base Address=500 Location(X[I])=Base Address+(I-1) Location(X[4])=500 +(4 -1) =503
Represent Two Dimensional Array • 1- Row – wise Method Location ( A[ i , j] )= base address +N *( i-1 )+( j-1 ) E.G :- A[5,7], M=5, N=7, Base Address=900 Find A[ 4 , 6 ] Location(A [I,J])=Base Address +N*(I-1)+(J-1) Location(A [4,6])=Base Address+7 *(4 -1)+(6 -1) =900+21+5 =926
2- Column – wise method Location(A [I,J])=Base Address + M *(J -1)+(I -1) E.g. A[5,7], M=5, N=7, Base Address=900 Find A[ 4 , 6 ] Location(A [4,6])=900 +5 *(6 -1)+(4 -1) =900+25+3 =928
#include<iostream.h> • intsort[5]; • intitem,i,j; • void main() • { • cout<<"enter elements of array "<<endl; • for(i=0;i<5;i++) • { • cin>>sort[i]; • } • item=0; • for(i=0;i<5;i++) • for(j=i+1;j<5;j++) • { • if(sort[j]<sort[i]) • item=sort[i]; • sort[i]=sort[j]; • sort[j]=item; • } • //output sorting array • cout<<"output sorrting array"<<endl; • for(i=0;i<5;i++) • cout<<sort[i]<<endl; • getch(); • }
Assignment -2- • 1- find the large number and small number in array ? • 2- find an element in array where K any element ?