[자료구조] linked list 이용하여 Queue 구현
본 자료는 5페이지 의 미리보기를 제공합니다. 이미지를 클릭하여 주세요.
닫기
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
해당 자료는 5페이지 까지만 미리보기를 제공합니다.
5페이지 이후부터 다운로드 후 확인할 수 있습니다.

목차

1. Linked list를 사용하여, Queue의 모든 연산을 구현하시오.
2. 원형 배열을 사용하여, Queue의 모든 연산을 구현하시오.
3. HW#1에서 구현한 ADT인 linked list를 이용하여, Queue를 구현하시오.

본문내용

= (Rear+1)%MAX;
Queue[Rear]=Item;
Count++;
}
}
// 큐 삽입
void queueClass::remove()// 맨 앞에 입력되었던 데이터 삭제 첫칸을 건너띔
{
if(Count > 0 )
{
Front = (Front + 1) % MAX;
Count--;
}
}
void main()
{
int i;
queueClass Now;
node *Temp;
Temp = new node;
cout << "Input your data " << endl;//데이터를 입력받는다.
for(i=1; i<=3; i++)
{
cin >> Temp->data;
Now.add(Temp->data);
}
while(1){
cout << "Choose what you want to do" << endl;
cout << "1. Insert Data" << endl;
cout << "2. GetFront "<< endl;
cout << "3. Print All"<< endl;
int num;
cin >> num;
if ( num == 1 ){// 다시 데이터입력 받기
cout << " Insert ";
cin >> Temp->data;
Now.add(Temp->data);
}
if ( num == 2 ){// GetFront 앞 데이터를 출력하고 출력된 노드는 삭제
printf( " GetFront ");
cout << Now.Queue[Now.Front] << endl;
Now.remove();
}
if (num == 3){// 입력된 데이터 모두 출력
cout << "Print out All Queue data" << endl;
Now.Temp=Now.Front;
for (int i = Now.Front; i<=Now.Rear; i++)
{
cout << Now.Queue[Now.Temp] << endl;
Now.Temp++;
}
}
}
cout << endl << endl;
}
3. HW#1에서 구현한 ADT인 linked list를 이용하여, Queue를 구현하시오.
ADTLinkedlist.c
#include
#include
// 구조체 선언
struct node
{
char name[5];
char email[30];
int tel; // 이름 메일 전화번호 선언
node *next;// 다음 노드의 주소를 가르킴
node *prev;
};
node *head; // head 첫 번째 노드
// 노드 초기화
void initList()
{
head = new node;
head->next = NULL;
}
void delete1(node* target){
node *right, *left;
right=target->prev;
left=target->next;
if(left==NULL){
right->next=NULL;
}
else{
right->next=left;
left->prev=right;
}
}
void delete2(node* target, int c_num){
node *right, *left;
while ( target->tel != c_num){
target=target->next;
}
right=target->prev;
left=target->next;
if(left==NULL){
right->next=NULL;
}
else{
right->next=left;
left->prev=right;
}
}
// 노드 삽입
// new 노드를 임시 저장소로 활용하고 new 노드를 리턴
node *insertNode(node *Target, node *aNode)
{
node *New;
New = (node*)malloc(sizeof(node));
*New = *aNode;
New->prev=Target;
New->next = NULL;
Target->next = New;
return New;
}
void main()
{
int i;
node *Now, *Temp;
initList();
Now = head;
Temp = (node*)malloc(sizeof( node));
printf( "이름 전화번호 메일을 입력해주세요.(Data Insert)\n" );
for(i=1; i<=3; i++)
{
scanf("%s %d %s", Temp->name , &Temp->tel , Temp->email);
Now = insertNode(Now,Temp);
}
while(1){
printf ( "원하시는 작업을 선택해주세요\n" );
printf ( "1. 정보를 추가합니다.(Insert)\n" );
printf ( "2. 정보를 삭제합니다.(Front)\n" );
printf ( "3. 지정한 전화번호의 정보를 삭제합니다.\n" );
printf ( "4. 전체 정보를 출력합니다.\n" );
int num;
scanf("%d", &num);
if ( num == 1 ){// Que의 Insert 역할을 한다. 쌓여있던 데이터들 뒤에
// 새로 데이터를 연결 한다.
printf ( " 정보를 입력해주세요 ");
scanf("%s %d %s", Temp->name , &Temp->tel , Temp->email);
Now = insertNode(Now,Temp);
}
if ( num == 2 ){// Que의 Front 역할을 한다. 출력 뒤 맨 앞 데이터 삭제.
printf ( " 정보를 삭제합니다. " );
Now=head->next;
printf ("%s %d %s", Now->name, Now->tel, Now->email);
delete1(Now);
}
if ( num == 3 ){
printf (" 삭제할 전화번호를 입력하세요 ");
int c_num;
scanf ("%d", &c_num);
Now=head->next;
delete2(Now,c_num);
}
if (num == 4){
//출력
for(Now=head->next; Now; Now=Now->next)
printf ("%s %d %s \n", Now->name , Now->tel, Now->email);
}
printf ( "\n");
}
}
  • 가격2,800
  • 페이지수16페이지
  • 등록일2012.04.15
  • 저작시기2012.3
  • 파일형식한글(hwp)
  • 자료번호#740039
본 자료는 최근 2주간 다운받은 회원이 없습니다.
청소해
다운로드 장바구니