สถิติการเข้าชม

วันเสาร์ที่ 1 สิงหาคม พ.ศ. 2552

DTS 04-15/07/52

สรุป
ลิงค์ลิสต์ (Linked List) เป็นวิธีการเก็บ ข้อมูลอย่างต่อเนื่อง
ของอิลิเมนต์ต่าง ๆโดยมีพอยเตอร์เป็นตัวเชื่อมต่อแต่ละอิลิเมนท์
เรียกว่าโนด (Node)ซึ่งในแต่ละโนดจะประกอบไปด้วย 2 ส่วน
คือData จะเก็บข้อมูลของอิลิเมนท์ และส่วนที่สอง
คือLink Field จะทำหน้าที่เก็บตำแหน่งของโนดต่อไปในลิสต์
ในส่วนของ data อาจจะเป็นรายการเดี่ยวหรือเป็นเรคคอร์ดก็ได้
ในส่วนของ link จะเป็นส่วนที่เก็บตำแหน่งของโหนดถัดไปในโหนด
สุดท้ายจะเก็บค่า Null ซึ่งไม่ได้ชี้ไปยังตำแหน่งใด ๆเป็นตัวบอกการ
สิ้นสุดของลิสต์ในลิงค์ลิสต์จะมีตัวแปรสำหรับชี้ตำแหน่งลิสต์
(List pointer variable)ซึ่งเป็นที่เก็บตำแหน่งเริ่มต้นของลิสต์ ซึ่งก็คือ
โหนดแรกของลิสต์นั่นเอง ถ้าลิสต์ไม่มีข้อมูล ข้อมูลในโหนดแรก
ของลิสต์จะเป็นNull


โครงสร้างข้อมูลแบบลิงค์ลิสต์โครงสร้างข้อมูลแบบลิงค์ลิสต์จะแบ่งเป็น
2 ส่วน คือ

1. Head Structure จะประกอบไปด้วย 3 ส่วนได้แก่จำนวนโหนดในลิสต์
(Count) พอยเตอร์ที่ชี้ไปยังโหนดที่เข้าถึง (Pos) และพอยเตอร์ที่ชี้ไปยัง
โหนด ข้อมูลแรกของลิสต์ (Head)

2. Data Node Structure จะประกอบไปด้วยข้อมูล(Data) และพอยเตอร์ที่
ชี้ไปยัง ข้อมูลตัวถัดไป

ฟังก์ชัน stdio.h และ iostream.h

#include
#include // clrscr();
void input () ;
void menu () ;
void showEmp();
int i;
int n;
int iEmp=1;
int number;
char select;
struct name {
char name[30];
char surname[40];
int age;
char position[40];
int height;
int weight;
char status[10];
char birthday[40];
}name1[50];
main()
{
while (select != '3'){
menu();
if (select == '1')
{
input();
number++;
}
else if (select == '2')
{
showEmp();
}
else if (select == '3')
break;
else
{
clrscr();
printf("=======================\n");
printf("You Insert Wrong Choice\n");
printf("=======================\n");
printf("Press any key to continue...");
fflush(stdin);
scanf("%c",select);
clrscr();
}
}
clrscr();
printf("Thanks");
return 0;}
void input(void)
{
clrscr();
printf(" ======== Insert Profile ======== \n");
printf("Name : ");
scanf("%s",&name1[iEmp].name);
printf("Surname :");
scanf("%s",&name1[iEmp].surname);
printf("Age : ");
scanf("%d",&name1[iEmp].age);
printf("Position : ");
scanf("%s",&name1[iEmp].position);
printf("Height : ");
scanf("%d",&name1[iEmp].height);
printf("Weight : ");
scanf("%d",&name1[iEmp].weight);
printf("Status : ");
scanf("%s",&name1[iEmp].status);
printf("Birthday : ");
scanf("%s",&name1[iEmp].birthday);
iEmp++;
clrscr();
}
void menu(void)
{
printf("Please Select Menu\n");
printf("==================\n\n");
printf("1.Insert Employee\n");
printf("2.List of Employee\n");
printf("3.Exit Program\n");
printf("> ");
fflush(stdin);
scanf("%c",&select);
}
void showEmp(void)
{
clrscr();
printf("Number Of Employee : %d \n\n",number);
n=1;
i=1;
printf("=====================\n");
while (i ");fflush(stdin);
scanf("%c",&select); // any key to continueclrscr();
}

#include // cin cout
#include // clrscr();
void input () ;
void menu () ;
void showEmp();
int i;
int n;
int iEmp=1;
int number;
char select;
struct name {char name[30];
char surname[40];
int age;
char position[40];
int height;
int weight;
char status[10];
char birthday[40];
}name1[50];
main()
{
while (select != '3')
{
menu();
if (select == '1')
{
input();
number++;
}
else if (select == '2')
{
showEmp();
}
else if (select == '3')
break;
else
{
clrscr();
cout<<"=======================\n"; cout<<"You Insert Wrong Choice\n"; cout<<"=======================\n"; cout<<"Press any key to continue..."; cin>>select;clrscr();
}
}
clrscr();
cout<<"Thanks"; return 0;} void input(void) { clrscr(); cout<<" ======== Insert Profile ======== \n"; cout<<"Name : "; cin>>name1[iEmp].name;
cout<<"Surname :"; cin>>name1[iEmp].surname;
cout<<"Age : "; cin>>name1[iEmp].age;cout<<"Position : "; cin>>name1[iEmp].position;cout<<"Height : "; cin>>name1[iEmp].height;cout<<"Weight : "; cin>>name1[iEmp].weight;cout<<"Status : "; cin>>name1[iEmp].status;cout<<"Birthday : "; cin>>name1[iEmp].birthday;
iEmp++;
clrscr();
}
void menu(void)
{
cout<<"Please Select Menu\n"; cout<<"==================\n\n"; cout<<"1.Insert Employee\n"; cout<<"2.List of Employee\n"; cout<<"3.Exit Program\n"; cout<<"> ";cin>>select;}
void showEmp(void)
{
clrscr();
cout<<"Number Of Employee :"< ";
cin>>select; // any key to continue
clrscr();
}

ไม่มีความคิดเห็น:

แสดงความคิดเห็น