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

Cấu Trúc Dữ Liêu

2 posters

Go down

Cool Cấu Trúc Dữ Liêu

Bài gửi by Admin Sun Mar 06, 2011 6:12 pm

Bài này tôi làm chỉ mang tính chất là tham khao thôi, vừa làm xong có lẻ còn rất nhiều lỗi, tôi không có nhiều time để mà chỉnh sửa. Tôi còn làm môn Phương Pháp Nghiên Cứu khoa Học nữa, môn nầy thì tôi bù chất,khổ cái thân hic hic Idea có anh em nào làm xong chưa post lên cho anh em tham khảo với.
Còn đây là bài Cấu trúc dữ liệu tôi vừa làm:

Code:

"#include<stdio.h>
#include<conio.h>
                            //  Cac ham cai dat;//
#define DoDai 100;
typedef string ElementType;
typedef int Position;
typedef struct {
                ElementType Elements[DoDai];
                Position Last;
                }  List;
typedef struct {
                ElementType Elements[DoDai];
                int  Top_idx;
                }  Stack;
typedef struct {
                ElementType Elements[DoDai];
                int  Front, Rear;
                } Queue;
                            //  Mot so ham co ban;//
void MakeNull_list(List *L) { L->Last=0;}
int Empty_List(List *L) { return L.Last==0;}
void MakeNull_Stack(Stack *S) { MakeNull_List(S);}
int Enpty_Stack(Stack S) { return Empty_List(S);}
MakeNull_Queue( Queue *Q) { Q->Front=-1; Q->Rear=-1;}
int Empty_Queue(Queue Q) { return Q.Front==-1;}
                                        //Cat chuoi vao danh sach;//
void StringToList( Char *Str, List *L)
{
    MakeNull_List(L);
    ElementType Word;
    int i,len;
    len=strlen(Str);
    i=0;
    while (i<len)
      { Word=(char*)malloc(10);
        scanf(Str+i,"%s",Word);
        EnList(Word,L);
        i+=strlen(Word)+1;
      }
}
                                      // Nhap chuoi vao danh sach;//
void EnList(List *L, ElementType Word)
{
    Insert_List(Word;First_List(L);&L);
}
                                      // Nhap chuoi vao ngan xep;//
void EnStack(Stack *S; ElementType Word)
{
    Insert_List(Word,First(*S),&S);
}
                                      //  Nhap chuoi vao hang doi;//
void EnQueue( Queue *Q, ElementType Word)
{
    if (!Full_Queue(*Q))
    {  if (Empty_Queue(*Q))      Q->Front=0;
        Q->Rear=(Q->Rear+1) % Dodai;
        Q->Elements[Q->Rear]=Word;
    } else printf("Loi! Hang day!");
}
                                      //  Cat chuoi vao ngan xep;//
void StringToStack( Char *Str, Stack *S)
{
    MakeNull_List(S);
    ElementType Word;
    int i,len;
    len=strlen(Str);
    i=0;
    while (i<len)
      { Word=(char*)malloc(10);
        scanf(Str+i,"%s",Word);
        EnStack(Word,S);
        i+=strlen(Word)+1;
      }
}
                                      //  Cat chuoi vao hang doi;//
void StringToQueue( Char *Str, Queue *Q)
{
    MakeNull_List(Q);
    ElementType Word;
    int i,len;
    len=strlen(Str);
    i=0;
    while (i<len)
      { Word=(char*)malloc(10);
        scanf(Str+i,"%s",Word);
        EnQueue(Word,Q);
        i+=strlen(Word)+1;
      }
}
 
                                      // In mot danh sach;//
void Print_List(List *L)
{
    Position P;
    P=First_List(L);
    while (P!=End_List(L))
    { printf("%s",Retrieve(P,L));
      P=P->Next(P,L);
    }
}
                                      // In mot ngan xep;//
void Print_Stack(Stack *S)
{
    if(!Empty_Stack(S))
    printf("%s",return S.Elements[S.Top_idx];
    else printf("Loi! Ngan xep rong");
}
                                      //  In mot hang doi;//
void Print_Queue(Queue *Q)
{
    Position T;
    T=Q->Front;
    while(T!=End_List(Q))
    {  printf("%s", Front(Q));
        Q->Front=Q->Front->Next;
    }
}
                                      // CHUONG TRINH CHINH//
int main()
{
    string Str;
printf("nhap vao 1 chuoi"); //nhap 1 chuoi tu ban phim//
scanf("%s",&Str);
StringToList(Str,L);
StringToStack(Str,S);
StringToQueue(Str,Q);
printf(" in ra bang ket qua danh sach/n");
Print_List(L);
printf(" in ra bang ket qua ngan xep/n");
Print_Stack(S);
printf(" in ra bang ket qua hang doi/n");
Print_Queue(Q);
getch ();
return 0;
}"
Admin
Admin

Posts : 1013
Thanked : 47
Gia Nhập 25/08/2010

Tài Sản
Thú nuôi:

https://k4info.forumvi.com

Về Đầu Trang Go down

Cool Re: Cấu Trúc Dữ Liêu

Bài gửi by hiepsidanhthue Wed Aug 03, 2011 5:00 pm

Này các bạn. Nếu các bạn không giải được bài tập Cấu trúc dữ liệu, giải thuật, hay các thứ khác có liên quan đến chuyên ngành Tin học. Hãy liên hệ với chúng tôi để được kết quả tốt nhất với chi phí rẻ nhất.
avatar
hiepsidanhthue

Posts : 1
Thanked : 0
Gia Nhập 14/07/2011

Về Đầu Trang Go down

Về Đầu Trang

- Similar topics

 
Permissions in this forum:
Bạn không có quyền trả lời bài viết