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


descriptionHàng đợi có con trỏ (Help) EmptyHàng đợi có con trỏ (Help)

more_horiz
Đây là bài tập em đã làm nhưng có phát sinh lỗi, mong quý thầy cô hướng dẫn

Code:


#include <stdio.h>
#include<conio.h>
#include<malloc.h>
typedef struct Node{
   int Data;
   Node * Next;
};
typedef Node* Position;

typedef struct ReadyQueue{
   Position Front;
   Position Rear;
};
void init(ReadyQueue *rq){
   rq->Rear=NULL;
   rq->Front=NULL;
}
int isEmpty(ReadyQueue *rq){
   if (rq->Front==NULL) return 0; // hang doi rong
   else return 1; //hang doi khong rong
}
void AddProcess(ReadyQueue *rq, int pid)
{
   if(isEmpty(&(*rq))) // Hang khong rong
   {
      Position P;
      P=(Node*)malloc(sizeof(Node));
      P->Data=pid;
      rq->Front=P;
      rq->Rear=P;
      P->Next=NULL;
   }
   else
   {   Position P;
      P=(Node*)malloc(sizeof(Node));
      P->Data=pid;
      P->Next=NULL;
      rq->Rear->Next=P;
      rq->Rear=P;
   }
}
int removeProcessQueue(ReadyQueue *rq)
{
   int temp;
   if(!isEmpty(&(*rq)))
   {
      temp=rq->Front->Data;
      rq->Front=rq->Front->Next;

   }
   return temp;
}
int FrontList(ReadyQueue *rq){
   return (rq->Front->Data);
}
void listProcess(ReadyQueue rq)
{
   while(!isEmpty(&rq))
   {

      printf("%d ",FrontList);
      removeProcessQueue(&rq);
   }
}
void main(){
   clrscr();
   ReadyQueue rq;

   init(&rq);
   printf("bat dau in du lieu: ");
   AddProcess(&rq,10);
   //AddProcess(&rq,20);
   //AddProcess(&rq,30);
   //AddProcess(&rq,40);
   //AddProcess(&rq,50);
   //AddProcess(&rq,60);
   //AddProcess(&rq,70);
   listProcess(rq);
   getch();

}


descriptionHàng đợi có con trỏ (Help) EmptyRe: Hàng đợi có con trỏ (Help)

more_horiz
Em bị lỗi j? Em xem code mẫu trong mục cấu trúc dữ liệu.
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