IT05
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.

IT05

Lớp CNTT05A - ĐH Đồng Tháp
 
Trang ChínhPortalGalleryLatest imagesTìm kiếmĐăng kýĐăng Nhập

 

 Queue - Chuyen Hau to sang trung to

Go down 
Tác giảThông điệp
nebulafire

nebulafire


Tổng số bài gửi : 25
Join date : 06/02/2010
Age : 37

Queue - Chuyen Hau to sang trung to Empty
Bài gửiTiêu đề: Queue - Chuyen Hau to sang trung to   Queue - Chuyen Hau to sang trung to I_icon_minitimeThu Feb 25, 2010 7:51 am

Code:

#include <stdlib.h>
#include <string.h>
#include<stdio.h>
#include<conio.h>
#define elem char
typedef struct nodet {
   elem data;
   struct nodet *next;
    } node;
typedef node *nodeptr;
typedef struct {
   nodeptr front, rear;
    } queue;
void createqueue(queue &q)
{
    q.front = NULL;
}

int emptyqueue(queue q)
{
    return q.front == NULL;
}

void addqueue(queue &q, elem &x)
{
    nodeptr newp = new node;
    memcpy(&newp->data, &x, sizeof(elem));
    newp->next = NULL;
    if (q.front == NULL)
   q.front = newp;
    else
   q.rear->next = newp;
    q.rear = newp;
}

void removequeue(queue &q, elem &x)
{
    nodeptr t = q.front;
    if (q.front == NULL) exit(0);
    q.front = t->next;
    memcpy(&x, &t->data, sizeof(elem));
    delete t;
}
int laKytu(char kytu){
   return ( kytu=='+' ||  kytu=='-' ||  kytu=='*' ||  kytu=='/' ||  kytu=='(' ||  kytu==')');
}

//    23+4*5/ = (2+3) *4/5
void PostfixToInfix(char *bt){
   queue qso,qkyso,qkq;
   int len = strlen(bt);
   int i;
   char infixstr[100];
   char temp,pushval;
   createqueue(qso);
   createqueue(qkyso);
   createqueue(qkq);
   for (i = 0; i <len; ++i){
      if (!laKytu(bt[i])){
         addqueue(qso, bt[i]);
      }
      else{
         addqueue(qkyso, bt[i]);
      }
   }
   while (!emptyqueue(qso)){
      removequeue(qso,temp);
      printf("%c",temp);
      if (!emptyqueue(qkyso)){
         removequeue(qkyso,temp);
         printf("%c",temp);
      }
   }
}

void main()
{
   char bt[100];
   printf("\nNhap mot bieu thuc hau to hop le (trong de thoat): ");
   gets(bt);
   if (strlen(bt) > 0)
      PostfixToInfix(bt);
    getch();

}

Về Đầu Trang Go down
 
Queue - Chuyen Hau to sang trung to
Về Đầu Trang 
Trang 1 trong tổng số 1 trang
 Similar topics
-
» Chuyển trung tố sang hậu tố
» chổ này nói chuyện tự do phải hông?
» gửi bạn trung!
» Nguyễn Minh Trung
» 7/2/2009 Tap trung truoc cong truoc hop lop

Permissions in this forum:Bạn không có quyền trả lời bài viết
IT05 :: SOURCE - CODE CHƯƠNG TRÌNH :: C/C++-
Chuyển đến