Từ 1 tới 4 trên tổng số 4 kết quả

Đề tài: Xây Dựng 1 Hàm Tra Từ điển

  1. #1
    Ngày gia nhập
    12 2007
    Bài viết
    3

    Wink Xây Dựng 1 Hàm Tra Từ điển

    em viết mãi vẫn ko được
    đề tài của em là như này
    xây dựng hệ thống từ điển sư dụng danh sách liên kết đơn
    em viết gần xong rùi chỉ còn mỗi phần tra từ điển thui mà mãi ko được các pác giúp em 1 tay với

  2. #2
    Ngày gia nhập
    01 2008
    Bài viết
    41

    từ điển mà dùng linked list thì hơi lạ,còn việc tra từ điển thì chỉ là một hàm search bình thường thôi,mỗi node sẽ có 2 trường là definition và word,bạn dùng hàm search theo word thôi

  3. #3
    Ngày gia nhập
    12 2007
    Bài viết
    3

    Trích dẫn Nguyên bản được gửi bởi huybka Xem bài viết
    từ điển mà dùng linked list thì hơi lạ,còn việc tra từ điển thì chỉ là một hàm search bình thường thôi,mỗi node sẽ có 2 trường là definition và word,bạn dùng hàm search theo word thôi
    thanks bạn nhiều
    mình đã viết được nhưng có 1 vấn đề là tra từ anh ra việt thì được còn ngược lại thì ko .
    và 1 phần nữa là : sửa từ đã có (sửa nội dung 1 từ khi đã biết từ tiếng anh)
    mình post bài mình làm lên . các bạn xem rùi sửa giúp mình với nha

    bài toán là xấy dựng hàm tra từ điển
    1 : tạo danh sách từ
    2 : chèn từ mới vào danh sách
    3 : xóa 1 từ khỏi từ điển
    4 : sắp xếp từ điển
    5 : tra từ điển dã có
    6 : liệt kê các từ đã có
    7 : sửa từ đã có (sửa nội dung 1 từ khi đã biết từ tiếng anh)

    đây là bài làm của mình ===> các bạn sửa giúp mình với nha
    thanks nhiều
    --------------------------------------------------------------------------
    PHP Code:
    #include<conio.h>
    #include<stdio.h>
    #include<string.h>
    #include <dos.h>
    #include <iostream.h>
    #include <iostream.h>
    #include <stdlib.h>
    #include <io.h>
    //-----------------------------------------------------------------------------//

    struct data
    {
     
    char tu[25];
     
    char nghia[50];
    } ;
    struct node
    {
    data info;
    struct node next;
    } ;
    struct list
    {
    node head;
    node tail;
    } ;
    list 
    Q//tao ds ten Q
    node new_element;
    data x//KB phan tu x can tim
    //------ Ham khoi tao 1 ds chua co pt nao -----------
    void khoitao(list &Q)
    {
    Q.head NULL;
    Q.tail NULL;
    }
    //--------------------------------
    node *get_node(data x)
    {
    node *p;
    p= (node*)malloc(sizeof(node));
    if (
    == NULL)
    {
    printf("Khong du bo nho !");
    exit(
    1);
    }
    else
    {
    -> info x;
    -> next NULL;
    }
    return 
    p;
    }

    void hien_thi(list Q)
    {
    node *p;
    Q.head;
    printf("\n%7s%7s","tu","nghia");
    printf("\n----------------------------------------------------------");
    while(
    p!= NULL)
    {
    printf("\n%4s",p->info.tu);
    printf("%12s",p->info.nghia);
    p-> next;
    }
    printf("\n\n");
    }
    //Ham de in thong tin du lieu trong mot nut cua danh sach
    void in(data x)
    {
    printf("\n%10s",x.tu);
    printf("%10s",x.nghia);

    }

    //Ham cho phep chen them phan tu moi vao dau danh sach
    void InsertFirst(list &Qnode *new_element)
    {
    if(
    new_element==NULL)
    {
    printf("Ko co phan tu de chen vao");
    exit(
    1);
    }
    else
    {
    if ( 
    Q.head == NULL //neu danh sach rong
    {
    Q.head new_element;
    Q.tail Q.head;
    }
    else 
    //danh sach khong rong
    {
    new_element -> next Q.head;
    Q.head new_element;
    }
    }
    }
    //------------------Chen 1 pt vao cuoi day----------------------------------
    void InsertLast(list &Q,node *new_element)
    {
    if (
    Q.head == NULL)
    {
    Q.head new_element;
    Q.tail Q.head; }
    else
    {
    Q.tail -> next new_element;
    Q.tail new_element; }
    }
    //-------------------Chen 1 phan tu moi vao sau pt q------------------------
    void InsertAfter(list &Qnode *qnode *new_element)
    {
    if( 
    q!=NULL)
    {
    new_element -> next -> next;
    -> next new_element;
    if (
    == Q.tailQ.tail new_element;
    }
    }
    //------------------Huy 1 pt o dau DS------------------------------------
    void RemoveHead( list &)
    {
    node *p;
    if (
    Q.head != NULL)
    Q.head;
    Q.head Q.head -> next;
    free(p);
    if ( 
    Q.head == NULL Q.tail NULL;
    }
    }
    //----------HUY PHAN TU DUNG SAU PHAN TU Q ------------
    void RemoveAfter(list &Qnode *)
    {
    node *p;
    if (
    != NULL)
    -> next;
    if (
    != NULL)
    {
    if (
    == Q.tail) { q->next NULLQ.tail q;}
    -> next -> next;
    free(p);
    }
    }
    else 
    RemoveHead(Q);
    }
    //---------HUY PHAN TU CO KHOA K - tu LA K ------------
    int RemoveNode(list &Q,char k[])
    node *Q.head;
    node *NULL;
    while( 
    != NULL)
    {
    if (
    strcmp(-> info.tu,k)==0) break;
    pp->next;
    }
    if (
    == NULL) return 0//Khong tim thay k
    if (!= NULL)
    {
    if(
    == Q.tailQ.tail q;
    q->next p->next;
    free(p);
    }
    else 
    //p la phan tu dau xau
    {
    Q.head -> next;
    if (
    Q.head == NULLQ.tail NULL;
    }
    return 
    1;
    }
    //------------------------------------
    node *Search(list &Q,char k[])
    node *p;
    Q.head;
    while (( 
    != NULL) && (strcmp(-> info.tu,k) != 0))
    -> next;
    return 
    p;
    }
    //--------------------------------
    //Ham sx danh sach cac tu theo thu tu tang dan
    void ListSortInterchange(list &Q)
    {

    node *p, *q//p và q la hai bien dieu khien
    data tg;
    Q.head;
    while (
    != NULL)
    {
    -> next;
    while(
    q!=NULL)
    {
    if(
    p->info.tu q->info.tu)
    {
    tg=p->info;
    p->info=q->info;
    q->info=tg;
    }
    q->next;
    }
    p=p->next;
    }
    }
    // ham them tu vao tu dien =-=--=-

    void chenmang(char *a[],int &n,char ch[])
    int i,h;
    a[n]=(char*)malloc(25);
    for(
    i=n;i>0;i--)
    {
    h=strcmpi(a[i-1],ch);
     if(
    h>0strcpy(a[i],a[i-1]);
     if(
    h<0) {strcpy(a[i],ch);break;}
    }
    if(
    i==0){strcpy(a[i],ch);}
    n++;
    }

    //-----------------------------------------------------------------------
    void main ()
    {
    int n//Xac dinh so phan tu dau tien cua tu dien duoc luu tru
    int ok;
    char select;
    khoitao(Q);
    clrscr ();
    do {
    printf("\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
    printf("\n+ +");
    printf("\n+ 0. dung chuong trinh +");
    printf("\n+ 1. tac gia +");
    printf("\n+ 2. tao danh sach tu dien +");
    printf("\n+ 3. chen mot tu vao danh sach +");
    printf("\n+ 4. xoa mot tu khoi tu dien +");
    printf("\n+ 5. tim 1 tu trong tu dien  +");
    printf("\n+ 6. TIM KIEM MOT PHAN TU TRONG DANH SACH +");
    printf("\n+ 7. SAP XEP DANH SACH +");
    printf("\n+ 8. sua tu dien +");

    printf("\n+ +");
    printf("\n+ ..:: PHAT TRIEN BOI le duy tung ::.. +");
    printf("\n+ +");
    printf("\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
    printf("\nban muon vao xem phan nao ? : ");
    scanf("%d",&select);
    switch (
    select)
    {
    case 
    0:
    { exit(
    1);
    break;
    }
    case 
    1printf("\n");
    printf("######################################");
    printf("\n@ @@@");
    printf("\n@ TAC GIA CUA BAI TAP : ");
    printf("\n@ Sinh Vien :LE DUY TUNG ");
    printf("\n@ Lop : CN1K6C ");
    printf("\n@ Home page : maiyeunguoi.go.to ");
    printf("\n@ @@@");
    printf("\n######################################");
    printf("\n\nCHON PHIM 0 DE TIEP TUC : ");
    printf("\n\nCHON PHIM 1-9 DE DUNG CHUONG TRINH: ");
    scanf("%d",&ok);
    break;
    case 
    2:
    {
    printf("\nNHAP DANH SACH - TAO PT DAU TIEN\n");
    printf("\n---------------------------------------------\n");
    printf("\n NHAP SO TU: ");
    scanf("%d",&n);
    for(
    int i=0;i<n;i++)
    //-------------------
    {
    printf("\ntu: "); scanf("%s",&x.tu);
    //-----------------------------
    printf("\nnghia: ");
    fflush(stdin);
    gets(x.nghia);
    new_element=get_node(x);
    InsertFirst(Q,new_element);
    // ----------------------------
    }
    printf("\n\nCHON PHIM 0 DE TIEP TUC : ");
    printf("\n\nCHON PHIM 1-9 DE DUNG CHUONG TRINH: ");
    scanf("%d",&ok);
    }
    break;
    case 
    :
    node *q;
    char ok1;
    char k[5];
    printf("\nTHEM PHAN TU VAO DANH SACH ");
    {
    printf("\n---------------------------------------------------------\n");
    printf("\n NHAP THONG TIN CAN BO SUNG VAO \n");
    printf("\ntu "); scanf("%s",&x.tu);
    //------------------------------------------
    // do {
    printf("\nnghia ");
    fflush(stdin);
    gets(x.nghia);

    //------------------------------------------
    new_element=get_node(x);
    printf("THEM : DAU = 1 - CUOI = 2 - SAU Q = 3");
    printf("\nXIN CHON CACH THEM: ");
    scanf("%s",&ok1);
    if (
    ok1 == '1')
    {
    InsertFirst(Q,new_element);
    printf("\n KET QUA DANH SACH DA DUOC BO SUNG \n");
    hien_thi(Q);
    printf("\n-------------------------------");
    }
    else if (
    ok1 == '2')
    {
    InsertLast(Q,new_element);
    printf("\n KET QUA DANH SACH DA DUOC BO SUNG \n");
    hien_thi(Q);
    printf("\n-------------------------------");
    }
    else if (
    ok1 == '3')
    {
    printf("Nhap tu dung truoc pt can them: ");
    scanf("%s",&k);
    node *q;
    Search(Q,k);
    InsertAfter(Q,q,new_element);
    printf("\n KET QUA DANH SACH DA DUOC BO SUNG \n");
    hien_thi(Q);
    printf("\n-------------------------------");
    }
    else
    printf("\nBAN DA NHAP SAI VUI LONG THUC HIEN LAI");

    //--------------------------------------------------------
    }
    printf("\n\nCHON PHIM 0 DE TIEP TUC : ");
    printf("\n\nCHON PHIM 1-9 DE DUNG CHUONG TRINH: ");
    scanf("%d",&ok);

    break;
    //---------------------------------------------------

    case 4//Huy phan tu dau danh sach
    printf("\nHUY PHAN TU TRONG DANH SACH ");
    printf("\n---------------------------------------------");
    char ok2;
    {
    printf("\nBAN MUON HUY PHAN TU NAO:\n");
    printf("\nPHAN TU DAU CHON 1");
    printf("\nPHAN TU SAU Q CHON 2");
    printf("\nPHAN TU KHOA K CHON 3");
    printf("\nCHON MOT CONG VIEC: ");
    scanf("%s",&ok2);
    if (
    ok2 == '1')
    printf("\n-------------------------------\n");
    RemoveHead(Q);
    printf("\n KET QUA DANH SACH DA BI XOA PHAN TU DAU \n");
    hien_thi(Q);
    printf("\n-------------------------------");
    }
    else if (
    ok2 == '2')
    char k[5];
    printf("\nHUY PHAN TU DUNG SAU PHAN TU Q");
    //Huy phan tu dung sau pt Q
    printf("\n-------------------------------\n");
    printf("\n Nhap tu can huy:");
    scanf("%s",&k);
    node *q;
    Search(Q,k);
    RemoveAfter(Q,q);
    printf("\n KET QUA DANH SACH DA BI XOA PHAN TU DAU \n");
    hien_thi(Q);
    printf("\n-------------------------------");
    }
    else if (
    ok2 == '3')
    {
    printf("\nHUY PHAN TU CO KHOA K - MSV LA K");
    //Tim kiem mot phan tu trong DS
    char k[5];
    printf("\n Nhap tu can tim kiem:");
    scanf("%s",&k);
    if(
    RemoveNode(Q,k) == -1)
    printf("\n Ko tim thay tu co nghia la %d trong DS",k);
    else {
    printf("\nDay co pt %s xuat hien tai vi tri thu %s",k,RemoveNode(Q,k)+1);
    hien_thi(Q); }
    printf("\n\nCHON PHIM 0 DE TIEP TUC : ");
    printf("\n\nCHON PHIM 1-9 DE DUNG CHUONG TRINH: ");
    scanf("%d",&ok);
    }
    }
    }
    //--------------------------------------------------
    break;
    case 
    5:
    printf("\ntra tu dien ");
    //Tim kiem mot phan tu trong DS
    char k[6];
    printf("\n Nhap tu can tra:");
    scanf("%s",&k);
    node *q;
    Search(Q,k);
    if(
    q==NULLprintf("\n Ko tim thay tu  %s trong DS",k);
    else
    {
    printf("\nCo tu  %s trong DS",k);
    printf("\n%12s%12s""tu","nghia");
    printf("\n---------------------------------------------------------------------");
    in(q->info);
    printf("\n");
    printf("\n---------------------------------------------------------------------");
    }
    printf("\n\nCHON PHIM 0 DE TIEP TUC : ");
    printf("\n\nCHON PHIM 1-9 DE DUNG CHUONG TRINH: ");
    scanf("%d",&ok);
    //---------------------------------------------------
    break;
    case 
    6:
    printf("\nSAP XEP DANH SACH");
    {
    printf("\n------------------------------- \n");
    ListSortInterchange(Q);
    printf("\n KET QUA DANH SACH SAU KHI SAP XEP \n");
    hien_thi(Q);
    printf("\n------------------------------- \n");
    }

    default:
    printf("\nBAN DA CHON SAI VUI LONG CHON LAI.\n");
    printf("\n\nCHON PHIM 0 DE TIEP TUC : ");
    printf("\n\nCHON PHIM 1-9 DE DUNG CHUONG TRINH: ");
    scanf("%d",&ok);

    //----------------------------------------------------

    }
    }
    } while (
    ok<= 0) ;
    getch();

    Bạn chú ý lần sau bỏ code vào thẻ code nhé :
    Code:
     php /php
    Đã được chỉnh sửa lần cuối bởi rox_rook : 11-02-2008 lúc 11:14 AM.

  4. #4
    Ngày gia nhập
    12 2007
    Bài viết
    3

    ọc sao chẳng thấy ai sửa giùm vậy
    chán vãi ah`

Quyền hạn của bạn

  • Bạn không thể gửi đề tài mới
  • Bạn không thể gửi bài trả lời
  • Bạn không thể gửi các đính kèm
  • Bạn không thể chỉnh sửa bài viết của bạn