Diễn đàn hỏi đáp học thuật - Download Tài Liệu Miễn Phí
Bạn có muốn phản ứng với tin nhắn này? Vui lòng đăng ký diễn đàn trong một vài cú nhấp chuột hoặc đăng nhập để tiếp tục.

Diễn đàn hỏi đáp học thuật - Download Tài Liệu Miễn PhíĐăng Nhập

VỮNG TIN - TIẾP BƯỚC - THÀNH CÔNG


descriptionThay oi!Sua bai dum em EmptyThay oi!Sua bai dum em

more_horiz

Code:

#include <stdio.h>
#include <conio.h>
#include <alloc.h>
typedef int ElementType;
typedef struct Node{
   ElementType Element;
   Node*Next;
};
typedef Node *Position;
typedef struct{
   Position Front,Rear;
}Queue;
void MakeNull_Queue(Queue *Q){
   Position Header=(Node*)malloc(sizeof(Node));
   Header->Next=NULL;
   Q->Front=Header;
   Q->Rear=Header;
}
char Empty_Queue(Queue Q){
   return Q.Front==Q.Rear;
}
Node *Make_Node(ElementType X){
   Node*temp=(Node*)malloc(sizeof(Node));
   temp->Element=X;
   return temp;
}
void EnQueue(Queue *Q,Node *P){
   Q->Rear->Next=P;
   Q->Rear=Q->Rear->Next;
   Q->Rear->Next=NULL;
}
Queue Input(int n){
   Queue L;
   MakeNull_Queue(&L);
   ElementType X;
   for(int i=0;i<n;i++){
      printf("\nPhan tu %d:\t",i);
      scanf("%d",&X);
      EnQueue(&L,Make_Node(X));
   }
   return L;
}
void Connect_Queue(Queue&Q,Queue L){
   Queue temp=L;
   while(!Empty_Queue(Q)){
      EnQueue(&Q,Make_Node(temp.Front->Next->Element));
      temp.Front=temp.Front->Next;
   }
}
void Out_Queue(Queue S){
   Queue temp=S;
   while(!Empty_Queue(temp)){
      printf("%d\t",temp.Front->Next->Element);
      temp.Front=temp.Front->Next;
   }
}
void main(){
   clrscr();
   int n,m,i;
   printf("Mhap n=");
   scanf("%d",&n);
   printf("Nhap hang:");
   Queue L,Q;
   MakeNull_Queue(&L);
   L=Input(n);
   printf("Hang vua nhap:\n\t");
   Out_Queue(L);
   MakeNull_Queue(&Q);
   printf("\nNhap Queue Q:");
   printf("\nSo phan tu:");
   scanf("%d",&m);
   Q=Input(m);
   printf("\nQueue Q vuq nhap");
   Out_Queue(Q);
   printf("\nQueue sau khi noi:");
   Connect_Queue(Q,L);
   Out_Queue(Q);
   getch();
}

descriptionThay oi!Sua bai dum em EmptyRe: Thay oi!Sua bai dum em

more_horiz
Sao bạn hông nêu nội dung của đề bài cho các bạn cùng sửa???
privacy_tip Permissions in this forum:
Bạn không có quyền trả lời bài viết
power_settings_newLogin to reply