Data Structure 7-05/08/52

วันอังคารที่ 25 สิงหาคม พ.ศ. 2552

ประโยชน์ที่ได้รับจากการเเรียนวิชาโครงสร้างข้อมูลครั้งที่ 7
1.ได้ความรู้พื้นฐานเกี่ยวกับโครงสร้างข้อมูลเรื่องคิว(Queue)อันได้แก่
1.1 ลักษณะการทำงานของคิวโดยคิวเป็นโครงสร้างข้อมูลแบบเชิงเส้นหรือลิเนียร์ลิสต์ซึ่งการเพิ่มเข้าของข้อมูลจะกระทำที่ปลายข้างหนึ่งโดยเรีัยกส่่วนท้ายว่าเรียร์(rear) และการนำออกข้อมูลจะกระทำที่ปลายข้างหนึ่งซึ่งเราเรียกว่าส่วนหน้าหรือฟรอนต์(front)
1.2 ลักษณะการทำงานของคิวเป็นลักษณะการเข้าก่อนออกก่อนหรือที่เราเรียกว่า FIFO
(First In First Out)

2.ได้ความรู้เกี่ยวกับการดำเนินการเกี่ยวกับคิว(Queue)อันได้แก่
2.1 Create Queue คือการสร้างคิวดดยกำหนดหน่วยความจำแก่คิว
2.2 Enqueue คือการเพิ่มข้อมูลลงไปในคิว
2.3 Dequeue คือการนำข้อมูลออกมาจากคิว
2.4 Queue Front คือการนำข้อมูลที่อยู่ส่วนต้นของคิวมาแสดง
2.5 Queue Rear คือการนำข้อมูลที่อยู่ในส่วนท้ายของคิวมาแสดง
2.6 Empty Queue คือการตรวจสอบคิวว่าคิวมีความจำว่างหรือไม่
2.7 Full Queue คือการตรวจสอบคิวว่าคิวมีความจำเต็มหรือไม่
2.8 Queue Count คือการนับจำนวนสมาชิกที่อยู่ในคิว
2.9 Destroy Queue คือการลบข้อมูลทั้งหมดที่อยู่ในคิว

3.มีความรู้ในการแก้ปัญหาของคิวโดยการสร้างคิวเป็นแบบวงกลม

4.สามารถนำคิวที่ได้เรียนจากวิชาโครงสร้างข้อมูลครั้งที่ 7 นี้ไปประยกต์ให้เกิดประโยชน์ในด้านคอมพิวเตอร์

Data structure 6-29/07/52

วันอังคารที่ 4 สิงหาคม พ.ศ. 2552

ประโยชน์ที่ได้รับจากการเรียนวิชาโครงสร้างข้อมูลครั้งที่ 6
1.ได้รับความรู้เกี่ยวกับโครงสร้างข้อมูลแบบสแตกมีการทำงานเป็นอย่างไร
2.ได้รับความรู้เกี่ยวกับการแทนที่ข้อมูลแบบสแตกอันได้แก่
2.1 การแทนที่ข้อมูลของสแตกแบบลิงค์ลิสต์
2.2 การแทนที่ข้อมูลของสแตกแบบอะเรย์
3.ได้รับความรู้เกี่ยวกับการทำงานของดำเนินงานของสแตกและสามารถทำการดำเนินงานของสแกได้อันได้แก่
3.1 Create Stack
3.2 Push Stack
3.3 Pop Stack
3.4 Stack Top
3.5 Empty Stack
3.6 Full Stack
3.7 Stack Count
3.8 Destroy Stack
4.ได้รับความรู้เกี่ยวกับการแปลงค่านิพจน์ทางคณิตศาสตร์ ประกอบด้วย 3 รูปแบบได้แก่
4.1 Infix
4.2 Postfix
4.3 Prefix

Data structure 5-22/07/52

วันอังคารที่ 28 กรกฎาคม พ.ศ. 2552

ประโยชน์ที่ได้รับจากการเรียนวิชาโครงสร้างครั้งที่ 5

1.ได้ทราบถึงโครงสร้างข้อมูลแบบสแตก (Stack) ว่ามีความหมายอย่างไร

2.ได้ทราบถึงวิธีการดำเนินงานขั้นพื้นฐานของโครงสร้างแบบสแตกอันได้แก่

2.1.Push คือการนำข้อมูลใส่ลงไปในสแตก

2.2.Pop คือการนำข้อมูลออกจากส่วนบนสุดของสแตก

2.3.Stack Top คือการคัดลอกข้อมูลที่อยู่บนสุดของสแตก แต่ไม่ได้เอาข้อมูลนั้นออกจาก

สแตก

ตัวอย่าง Stack ในชีวิตประจำวัน

สแตกเป็นโครงสร้างข้อมูลชนิดหนึ่งซึ่งมีการจัดการข้อมูลแบบ LIFO ( Last In First Out ) คือ ลำดับของข้อมูลที่ถูกนำมาเก็บก่อนจะถูกนำไปใช้ทีหลัง

เช่น การบรรจุลูกกระสุนปืนลงในแมกซีนลูกที่บรรจุหลังสุดจะถูกยิงออกมาก่อน

Data structure 4-15/07/52

วันอังคารที่ 21 กรกฎาคม พ.ศ. 2552

สรุปประโยชน์ที่รับจากการเขียนโปรแกรมคอมพิวเตอร์ประเภทลิงค์ลิส
1.ได้ความรู้เกี่ยวกับโครงสร้างข้อมูลแบบลิงค์ลิสต์
2.ได้ความรู้เกี่ยวกับกระบวนงานและฟังก์ชั่นที่ใช้ดำเนินงานพื้นฐานโครงสร้างข้อมูลแบบลิงค์ลิสต์
3.สามารถนำความรู้ที่้ได้ศึกษาการสร้างลิงค์ลิสต์มาประยุกต์ใช้ในการเขียนโปรแกรมได้
4.สามารถสร้างโครงสร้างข้อมูลลิงค์ลิสต์แบบซับซ้อนได้

ตัวอย่างการเปรียบเทียบโครงสร้างโปรแกรมภาษา C กับ โปรแกรมภาษา C++
Ex โปรแกรมภาษาC
/*Program by Jormpon:Do not copy*/
/*Body Mass index*/
#include"stdio.h"
main()
{
float weight,height;
float bmi;
printf("Enter your weight (Kg): ");
scanf("%f",&weight);
printf("Enter your height (Metre): ");
scanf("%f",&height);

bmi=weight/(height*height);

if (bmi>40)
{
printf("Your Body Mass Index is %.3f\n",bmi);
printf("You are Morbidly obese.\n\n\n\n");
printf("By Jormpon");
}
else if (bmi>=27)
{
printf("Your Body Mass Index is %.3f\n",bmi);
printf("You are Obese.\n\n\n\n");
printf("By Jormpon");
}
else if (bmi>=23)
{
printf("Your Body Mass Index is %.3f\n",bmi);
printf("You are Overweight.\n\n\n\n");
printf("By Jormpon");
}
else if (bmi>=18)
{
printf("Your Body Mass Index is %.3f\n",bmi);
printf("You are Normal.\n\n\n\n");
printf("By Jormpon");
}
else if (bmi>=15)
{
printf("Your Body Mass Index is %.3f\n",bmi);
printf("You are Underweight.\n\n\n\n");
printf("By Jormpon");
}
else
{
printf("Your Body Mass Index is %.3f\n",bmi);
printf("You are Starvation.\n\n\n\n");
printf("By Jormpon");
}
}


Ex โปรแกรมภาษา C++
/*Program by Jormpon:Do not copy*/
/*Body Mass index*/
#include"iostream.h"
#include"iomanip.h"
main()
{
float weight,height;
float bmi;

cout<<"Enter your weight (Kg): "; cin>>weight;
cout<<"Enter your height (Metre): "; cin>>height;

bmi=weight/(height*height);

if (bmi>40)
{
cout<<"Your Body Mass Index is : "<<>=27)
{
cout<<"Your Body Mass Index is : "<<>=23)
{
cout<<"Your Body Mass Index is : "<<>=18)
{
cout<<"Your Body Mass Index is : "<<>=15)
{
cout<<"Your Body Mass Index is : "<< setprecision(5)<< bmi;
cout<<"\nYou are Underweight.";
cout<<"\n\n\n\nBy Jormpon";
}
else
{
cout<<"Your Body Mass Index is : "<< setprecision(5)<< bmi;
cout<<"\nYou are Starvation.";
cout<<"\n\n\n\nBy Jormpon";
}
}

Data structure 3-01/07/52

วันอังคารที่ 14 กรกฎาคม พ.ศ. 2552

ประโยชน์ที่รับจากการเรียนครั้งที่ 3


ได้รับความรู้เกี่ยวกับ Pointer เป็นตัวแปรชนิดหนึ่งที่ทำหน้าที่เก็บตำแหน่งที่อยู่ (Address) ของตัวแปรที่อยู่ในหน่วยความจำ และสามารถนำ Pointer ไปใช้ในการเขียนโปรแกรมภาษาซีได้


แบบฝึกหัด

1. ให้นักศึกษากำหนดค่าของ Array 1 มิติ และ Array 2 มิติ

EX ตัวอย่าง Array 1 มิติ

#include"stdio.h"
main()
{
int temp[31],i,min,max,avg;
int days;
printf("How many days in the month? ");
scanf("%d",&days);

for(i=0;itemp[i]) min=temp[i];
if(max

Ex ตัวอย่าง Array 2 มิติ

#include "stdio.h"

int x,y;

int sc[35][8];

void input_data()

{

for(y=0;y<=34;y++)

{

printf("student %d\n",y+1);

printf("Data structure = ");

scanf("%d",&sc[y][0]);

printf("Economic macro = ");

scanf("%d",&sc[y][1]);

printf("Analysis = ");

scanf("%d",&sc[y][2]);

printf("Accouting = ");

scanf("%d",&sc[y][3]);

printf("Business Ethics = ");

scanf("%d",&sc[y][4]);

printf("Prepare to Job = ");

scanf("%d",&sc[y][5]);

printf("Business Analysis = ");

scanf("%d",&sc[y][6]);

sc[y][7] = sc[y][0]+sc[y][1]+sc[y][2]+sc[y][3]+sc[y][4]+sc[y][5]+sc[y][6];

}

}

void main()

{

input_data();

for(x=0;x<=34;x++)

printf("Student %d Sumation of point = %d\n",x+1,sc[x][7]);

}


2. ให้นักศึกษาหาค่าของ A[2], A[6] จากค่า A={2,8,16,24,9,7,3,8}

ค่าของ A[2]=16

ค่าของ A[6]=3


3. จากค่าของ int a[2][3] = {{6,5,4},{3,2,1}};ให้นักศึกษา หาค่าของ a[1][0] และ a[0][2]

ค่าของa[1][0]=3

ค่าของa[0][2]=4


4. ให้นักศึกษากำหนด Structure ที่มีค่าของข้อมูลอย่างน้อย6 Records

#include "stdio.h"
int i;
long sum1,sum2,sum3;
main()
{
struct National_Product
{

long quality;
long price;
}np;

struct National_Income
{
long rent;
long payment;
long interest;
long profit;
}ni;
struct National_Expenditure
{
long consume;
long invest;
long government;
long net_export;
}ne;
{
printf("1 National product,2 National income,3 National expenditure\n");
printf("Choose your choice between 1 and 3 : ");
scanf("%d",&i);
switch(i)
{
case 1: printf("National income data\n");
printf("Enter number of product: ");
scanf("%d",&np.quality);
printf("Enter price : ");
scanf("%d",&np.price);

sum1 =(np.quality*np.price);
printf("National income of product is %d\n",sum1);
break;
case 2: printf("National income data\n");
printf("Enter all of rent : ");
scanf("%d",&ni.rent);
printf("Enter all of payment : ");
scanf("%d",&ni.payment);
printf("Enter all of interest : ");
scanf("%d",&ni.interest);
printf("Enter all of profit : ");
scanf("%d",&ni.profit);

sum2 =(ni.rent+ni.payment+ni.interest+ni.profit);
printf("National income of income is %d\n",sum2);
break;
case 3: printf("National income data\n");
printf("Enter all of consumption : ");
scanf("%d",&ne.consume);
printf("Enter all of investment : ");
scanf("%d",&ne.invest);
printf("Enter all of government : ");
scanf("%d",&ne.government);
printf("Enter all of net export : ");
scanf("%d",&ne.net_export);

sum3 =(ne.consume+ne.invest+ne.government+ne.net_export);
printf("National income of expenditure is %d\n",sum3);
break;
default:
printf("U N K N O W N C O M M A N D ! ! ");
}
}
}



5. ให้นักศึกษาบอกความแตกต่างของการกำหนดตัวชนิด Array กับตัวแปร Pointer ในสภาพของการกำหนดที่อยู่ของข้อมูล

ตัวแปรพอยเตอร์มีประโยชน์ในการลดปริมาณหน่วยความจำที่ต้องใช้ในการเขียนโปรแกรม โดยการส่งข้อมูลในรูปพอยเตอร์ เข้าไปในฟังก์ชันที่โปรแกรมเรียกพร้อมกันหลายฟังก์ชัน แทนการส่งข้อมูลในรูปตัวแปรธรรมดา ซึ่งต้องใช้ตัวแปรหลายตัว
ตัวแปรพอ ยเตอร์มีลักษณะคล้ายตัวแปรตารางอาเรย์ แต่ที่แตกต่างกันคือ ตัวแปรตารางอาเรย์จะเก็บเฉพาะค่าต่างๆ ที่เป็นชนิดกันเดียวกับตัวแปรอาเรย์แต่ ตัวแปรพอยเตอร์จะเก็บเฉพาะค่าตำแหน่ง Address ตัวแปรเท่านั้น โดยไม่ได้มีการจัดเตรียมหน่วยความจำแบบไดนามิกส์ (Dynamic Memory Allocation) ไว้