Algorithm & programming part V (Data Structure)

Huh….guys, In this meeting i’m gonna share with you about a little bit of my experience. Some hours ago, i’ve typed this articles until finish. Then my friend invite me to go to campus. A few minutes later, I resume my computer and reopen my articles. You know what happen ??? the data is dissapear, so that i’ve to write type it again. Hmm…. that’s unpleasure experience.

Actually 2 days ago the holiday has been begun for my major, but unfortunatelly I still have so many kinds of activities such as regional english seminar. Alhamdulillah the seminar run well. Guys , after the seminar attended, I plan to go home immediately but the leader of my organization said to me that “Bro , don’t go home, we’ll go to Pare”. Wow Kediri pare, Directly I know the purpose which is besides enjoying holiday, we’re gonna take english course . So, if you’re interested to join with us,you can contact me through facebook,okay…

Well, actually now we were in Data Structure topic. Data Structure is a fundamental item for a programmer to master. In data Structure we have so many topics . Below is the list :

  1. array
  2. Struct/ record
  3. Union (only in C)
  4. Pointer and static Variable
  5. stack
  6. Queue
  7. linked List
  8. Sorting
  9. Searching
  10. Tree
  11. Graph

That’s all the subtopics for data structure. The first we’re gonna talk about Array. Array is a finite ordered set of homogeneous elements. It means that , Array contains of a group of elements which has same type and. The amount of elements are determined and arranged. Array has 3 types : 1st is one dimension array, 2nd is two dimension array , 3rd is three dimension array. All of them have their own function. The 1st type is usually used for displaying common data. The 2nd type is usually used for displaying matrix and point location. The last type is usually used for displaying point location of 3 dimension object.

Below is examples for each types :

example program array 1 dimension :

PASCAL

program array_1_dimension;
uses crt;
var
a:array [1..10]of integer;
b,c:integer;
begin
write('input a number = ');read(b);
{input data}
 for c:=1 to b do
 begin
 write('index[',c,']=');read(a[c]);
 end;
{display data}
 for c:=1 to b do
 begin
 writeln(a[c]);
 end;
end.

C

#include<stdio.h>

int main(){
int c[10];
int a,b;
 printf("input a number = ");scanf("%d",&a);
 //input
 for (b=1; b<=a;b++){
 printf("index[%d] = ",b);scanf("%d",&c[b]);
 }
 //display
 for (b=1; b<=a;b++){
 printf("%d\n",c[b]);
 }
}

example array 2 dimension (Matrix) :

PASCAL

program array_2_dimension(matrix);
uses crt;
var
mat:array [1..10,1..10]of integer;
a,b,row,coloumn:integer;
begin
write('input a row = ');read(row);
write('input a coloumn = ');read(coloumn);
{input data}
 for a:=1 to row do
 begin
 for b:=1 to coloumn do
 begin
 write('index[',a,',',b,']=');read(mat[a,b]);
 end;
 end;
{display data}
 for a:=1 to row do
 begin
 for b:=1 to coloumn do
 begin
 write(mat[a,b]:3);
 end;
 writeln;
 end;
end.


C

#include<stdio.h>

int main(){
int mat[10][10],a,b,row,coloumn;
 printf("please input a row = ");scanf("%d",&row);
 printf("please input a coloumn = ");scanf("%d",&coloumn);
 for (a=1;a<=row;a++)    {
 for (b=1;b<=coloumn;b++){
 printf("index[%d,%d]=",a,b);scanf("%d",&mat[a][b]);
 }
 }
 for (a=1;a<=row;a++)    {
 for (b=1;b<=coloumn;b++){
 printf("%d  ",mat[a][b]);
 }
 printf("\n");
 }
}

example for 3 dimensions array :

PASCAL

program array_3_dimension(matrix);
uses crt;
var
mat:array [1..10,1..10,1..10]of integer;
a,b,c,x,y,z:integer;
begin
write('input x coordinate = ');read(x);
write('input y coordinate= ');read(y);
write('input z coordinate= ');read(z);
{input data}
 for a:=1 to x do
 begin
 for b:=1 to y do
 begin
 for c:=1 to z do
 begin
 write('index[',a,',',b,',',c,']=');read(mat[a,b,c]);
 end;
 end;
 end;
{display data}
 for a:=1 to x do
 begin
 for b:=1 to y do
 begin
 for c:=1 to z do
 begin
 write(mat[a,b,c]:3);
 end;
 writeln;
 end;
 writeln;
 end;
 writeln;
end.


C

#include<stdio.h>

int main(){
int mat[10][10][10],a,b,c,x,y,z;
 printf("please input x coordinate = ");scanf("%d",&x);
 printf("please input y coordinate = ");scanf("%d",&y);
 printf("please input z coordinate = ");scanf("%d",&z);
 for (a=1;a<=x;a++){
 for (b=1;b<=y;b++){
 for (c=1;c<=z;c++){
 printf("index[%d,%d,%d]=",a,b,c);scanf("%d",&mat[a][b][c]);
 }
 }
 }

 for (a=1;a<=x;a++){
 for (b=1;b<=y;b++){
 for (c=1;c<=z;c++){
 printf("%d  ",mat[a][b][c]);
 }
 printf("\n");
 }
 printf("\n");
 }
}


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: