Announcement

Collapse
No announcement yet.

anh chị giúp em lỗi này với !hjx

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • [C++] anh chị giúp em lỗi này với !hjx

    PHP Code:
    #include"conio.h"
    #include"stdio.h"
    typedef struct tagNode
    {
        
    int info;
        
    struct tagNode *pNext;
    }
    Node;
    typedef struct tagList
    {
        
    Node *pHead;
        
    Node *pTail;
    }List;
    void createList(List &l)
    {
        
    l.pHead=l.pTail=NULL;
    }
    NodegetNode(int x)
    {
        
    Nodep;
        
    p=new Node;
        if(
    p==NULL)return 0;
        else
        {
            
    p->info=x;
            
    p->pNext=NULL;
        }
        return 
    p;
    }
    void addTail(List &l,Node *p)
    {
        if(
    l.pHead==NULL)
        {
            
    l.pHead=p;
            
    l.pTail=l.pHead;
        }
        else
        {
            
    l.pTail->pNext=p;
            
    l.pTail=p;
        }

    }
    void addHead(List &l,Node *p)
    {
        if(
    l.pHead==NULL)
        {
            
    l.pHead=p;
            
    l.pTail=l.pHead;
        }
        else
        {
            
    p->pNext=l.pHead;
            
    l.pHead=p;
        }
    }
    void inds(List l)
    {
        
    Nodep;
        
    p=l.pHead;
        while(
    p)
        {
            
    printf("%d  ",p->info);
            
    p=p->pNext;
        }
    }
    int deleteHead(List &l)
    {
        
    int x;
        
    Node *p;
        
    p=l.pHead;
        
    x=p->info;
        if(
    p!=NULL)
        {
            
    l.pHead=l.pHead->pNext;
            
    delete(p);
            if(
    l.pHead==NULL)
                
    l.pTail=NULL;
            return 
    1;
        }
        return 
    0;
    }
    void deleteTail(List &l)
    {
        
    Node *p,*q;
        
    p=l.pHead;
        while(
    p!=l.pTail)
        {
            
    q=p;
            
    p=p->pNext;
        }
        if(
    p==l.pHead)
            
    deleteHead(l);
        else
        {
            
    l.pTail=q;
            
    q->pNext=NULL;
            
    delete(p);
        }
    }
    Nodeseachx(List l,int x)
    {
        
    Node *p;
        
    p=l.pHead;
        while((
    p!=NULL)&&(p->info!=x))
            
    p=p->pNext;
        return 
    p;
    }
    int timx(List l,int x)
    {
        
    Node *p;
        
    p=l.pHead;
        while((
    p!=NULL)&&(p->info==x))
            
    p=p->pNext;
        if(
    p==NULL)return 0;
        else
            return 
    1;
    }

    void insertafterq(List &l,Node *p,Node *q)
    {
        if(
    q!=NULL)
        {
            
    p->pNext=q->pNext;
            
    q->pNext=p;
            if(
    l.pTail==q)
                
    l.pTail=q;
        }
        else
            
    addHead(l,q);
    }
    void dao(List &l)
    {
        
    int x;
        
    Node *p,*k;
        List 
    q;
        
    createList(q);
        
    p=l.pHead;
        do
        {
            
    x=p->info;
            
    k=(getNode(x));
            
    addHead(q,k);
            
    p=p->pNext;
        }while(
    p!=NULL);
        
    createList(l);
        
    p=q.pHead;
        do
        {
            
    x=p->info;
            
    k=(getNode(x));
            
    addTail(l,k);
            
    p=p->pNext;
        }while(
    p!=NULL);
    }
    void sx(List &l)
    {
        
    Node *p,*k;
        
    p=l.pHead;
        while(
    p!=NULL)
        {
            
    k=p->pNext;
            while(
    k!=NULL)
            {
                if(
    k->info<p->info) {Hoan(k->info,p->info);}
                
    k=k->pNext;
            }
            
    p=p->pNext;
        }
                

    }
    void Hoan(int &a,int &b)
    {
        
    int c;
        
    c=a;
        
    a=b;
        
    b=c;
    }
    int main()
    {
        List 
    l;
        
    int x,a;
        
    Node *p;
        
    createList(l);
        do
        {
            
    printf("nhap phan tu x \n");
            
    scanf("%d",&x);
            if(
    x==0)break;
            
    p=(getNode(x));
            
    addTail(l,p);
        }while(
    1);
        
    inds(l);
        
    sx(l);
        
    inds(l);
        
    /**printf("nhap so x muon chen sau no \n");
        scanf("%d",&x);
        printf("nhap so can chen a \n");
        scanf("%d",&a);
        insertafterq(l,getNode(a),seachx(l,x));
        inds(l);
        printf("\n");
        deleteHead(l);
        inds(l);
        printf("\n");
        deleteTail(l);
        inds(l);
        printf("\n");**/
        
    getch();
        return 
    0;
    }
    mấy anh xem giúp em hàm sx nha nó báo lổi "nhận dạng không tìm thấy" ở hàm hoan(); 
    Last edited by toannv; 30-04-2012, 18:48.

  • #2
    Lôi đầu cái hàm void Hoan(int &a,int &b) đó lên phía trên, em phải khai báo trước rồi mới được sử dụng tại void sx(List &l)

    Lần sau chèn code PHP vào em ạ :

    PHP Code:
    #include"conio.h"
    #include"stdio.h"
    typedef struct tagNode
    {
    int info;
    struct tagNode *pNext;
    }
    Node;
    typedef struct tagList
    {
    Node *pHead;
    Node *pTail;
    }List;
    void createList(List &l)
    {
    l.pHead=l.pTail=NULL;
    }
    NodegetNode(int x)
    {
    Nodep;
    p=new Node;
    if(
    p==NULL)return 0;
    else
    {
    p->info=x;
    p->pNext=NULL;
    }
    return 
    p;
    }
    void addTail(List &l,Node *p)
    {
    if(
    l.pHead==NULL)
    {
    l.pHead=p;
    l.pTail=l.pHead;
    }
    else
    {
    l.pTail->pNext=p;
    l.pTail=p;
    }

    }
    void addHead(List &l,Node *p)
    {
    if(
    l.pHead==NULL)
    {
    l.pHead=p;
    l.pTail=l.pHead;
    }
    else
    {
    p->pNext=l.pHead;
    l.pHead=p;
    }
    }
    void inds(List l)
    {
    Nodep;
    p=l.pHead;
    while(
    p)
    {
    printf("%d ",p->info);
    p=p->pNext;
    }
    }
    int deleteHead(List &l)
    {
    int x;
    Node *p;
    p=l.pHead;
    x=p->info;
    if(
    p!=NULL)
    {
    l.pHead=l.pHead->pNext;
    delete(p);
    if(
    l.pHead==NULL)
    l.pTail=NULL;
    return 
    1;
    }
    return 
    0;
    }
    void deleteTail(List &l)
    {
    Node *p,*q;
    p=l.pHead;
    while(
    p!=l.pTail)
    {
    q=p;
    p=p->pNext;
    }
    if(
    p==l.pHead)
    deleteHead(l);
    else
    {
    l.pTail=q;
    q->pNext=NULL;
    delete(p);
    }
    }
    Nodeseachx(List l,int x)
    {
    Node *p;
    p=l.pHead;
    while((
    p!=NULL)&&(p->info!=x))
    p=p->pNext;
    return 
    p;
    }
    int timx(List l,int x)
    {
    Node *p;
    p=l.pHead;
    while((
    p!=NULL)&&(p->info==x))
    p=p->pNext;
    if(
    p==NULL)return 0;
    else
    return 
    1;
    }

    void insertafterq(List &l,Node *p,Node *q)
    {
    if(
    q!=NULL)
    {
    p->pNext=q->pNext;
    q->pNext=p;
    if(
    l.pTail==q)
    l.pTail=q;
    }
    else
    addHead(l,q);
    }
    void dao(List &l)
    {
    int x;
    Node *p,*k;
    List 
    q;
    createList(q);
    p=l.pHead;
    do
    {
    x=p->info;
    k=(getNode(x));
    addHead(q,k);
    p=p->pNext;
    }while(
    p!=NULL);
    createList(l);
    p=q.pHead;
    do
    {
    x=p->info;
    k=(getNode(x));
    addTail(l,k);
    p=p->pNext;
    }while(
    p!=NULL);
    }

    void Hoan(int &a,int &b)
    {
    int c;
    c=a;
    a=b;
    b=c;
    }
    void sx(List &l)
    {
      
    Node *p,*k;
      
    p=l.pHead;
      while(
    p!=NULL)
    {
    k=p->pNext;
    while(
    k!=NULL)
    {
    if(
    k->info<p->info) {Hoan(k->info,p->info);}
    k=k->pNext;
    }
    p=p->pNext;
    }


    }

    int main()
    {
    List 
    l;
    int x,a;
    Node *p;
    createList(l);
    do
    {
    printf("nhap phan tu x \n");
    scanf("%d",&x);
    if(
    x==0)break;
    p=(getNode(x));
    addTail(l,p);
    }while(
    1);
    inds(l);
    sx(l);
    inds(l);
    /**printf("nhap so x muon chen sau no \n");
    scanf("%d",&x);
    printf("nhap so can chen a \n");
    scanf("%d",&a);
    insertafterq(l,getNode(a),seachx(l,x));
    inds(l);
    printf("\n");
    deleteHead(l);
    inds(l);
    printf("\n");
    deleteTail(l);
    inds(l);
    printf("\n");**/
    getch();
    return 
    0;

    Last edited by 08520206; 29-04-2012, 22:10.

    Comment


    • #3
      Bạn nên sử dung công cụ debug để kiểm tra,nó rất hữu ích đây!
      University of Information Technology - VNU HCM
      Student of Faculty of Computer Engineering
      Email : truong.ngohieu@gmail.com
      Tel : 0962 306 517

      Comment


      • #4
        thanks anh nhiều nha, gấp quá em không để ý, gửi rồi mới thấy

        Comment


        • #5
          lổi này là gì thế mấy anh
          PHP Code:
          #include"conio.h"
          #include"stdio.h"
          typedef struct tagDNode
          {
              
          int info;
              
          struct tagDNode *pPre;
              
          struct tagDNode *pNext;
          }
          DNode;
          typedef struct tagDList
          {
              
          DNode *pHead;
              
          DNode *pTail;
          }
          DList;
          void createDList(DList &l)
          {
              
          l.pHead=l.pTail=NULL;
          }
          DNodegetDNode(int x)
          {
              
          DNode *p;
              
          p=new DNode;
              if(
          p!=NULL)
              {
                  
          p->info=x;
                  
          p->pNext=NULL;
                  
          p->pPre=NULL;

              }
              else
                  return 
          0;
          }
          void addHead(DList &l,DNode *p)
          {
              if(
          l.pHead==NULL)
              {
                  
          l.pHead=p;
                  
          l.pTail=l.pHead;
              }
              else
              {
                  
          p->pNext=l.pHead;
                  
          l.pHead->pPre=p;
                  
          l.pHead=p;
              }
          }
          int main()
          {
              
          int x;
              
          DNode *p;
              
          DList l;
              
          createDList(l);
              do
              {
                  
          printf("nhap x\n");
                  
          scanf("%d",&x);
                  if(
          x==0)break;
                  
          p=getDNode(x);
                  
          addHead(l,p);

              }while(
          p);
              
          getch();
              return 
          0;

          1>C:\Users\ruacon\documents\visual studio 2010\Projects\huy\Debug\huy.exe : fatal error LNK1169: one or more multiply defined symbols found
          một hoặc nhiều định nghĩa được tìm thấy?!
          chương trình đơn giản mà còn sai nữa mấy anh giúp em với

          Comment


          • #6
            Sai hàm này rồi nè
            PHP Code:
            DNodegetDNode(int x)
            {
                
            DNode *p;
                
            p=new DNode;
                if(
            p!=NULL)
                {
                    
            p->info=x;
                    
            p->pNext=NULL;
                    
            p->pPre=NULL;

                }
                else
                    return 
            0;

            Có thể đại học không là cánh cửa duy nhất để vào đời, nhưng trước khi bạn đủ lớn để biết mình muốn gì thì đại học là "tấm vé" bảo đảm rằng bạn có ít nhất một giá trị.

            Comment


            • #7
              em sửa lại :
              PHP Code:
              DNodegetDNode(int x)
              {
                  
              DNode *p;
                  
              p=new DNode;
                  if(
              p!=NULL)
                  {
                      
              p->info=x;
                      
              p->pNext=NULL;
                      
              p->pPre=NULL;
                      return 
              p;
                  }
                  else
                      return 
              0;

              vẫn báo lổi cũ

              Comment


              • #8
                1>C:\Users\ruacon\documents\visual studio 2010\Projects\huy\Debug\huy.exe : fatal error LNK1169: one or more multiply defined symbols found
                một hoặc nhiều định nghĩa được tìm thấy?!
                chương trình đơn giản mà còn sai nữa mấy anh giúp em với
                Code Block chạy không lỗi

                Comment


                • #9
                  xóa hết trong thư mục debug rồi chạy lại
                  Bùm, Maria Ozawa Bin Laden, chuyên gia cưa bom hàng đầu Việt Nam
                  Bùm, Maria Ozawa Bin Laden, chuyên gia cưa bom hàng đầu Việt Nam
                  Bùm, Maria Ozawa Bin Laden, chuyên gia cưa bom hàng đầu Việt Nam
                  Bùm, Maria Ozawa Bin Laden, chuyên gia cưa bom hàng đầu Việt Nam
                  ...

                  Comment


                  • #10
                    anh có thể giải thích rõ lý do để lần sao em còn tự sửa ạ

                    Comment


                    • #11
                      xóa hết trong thư mục debug rồi chạy lại
                      em đã xóa hết rồi cho chạy lại nó vẫn báo lổi cũ, kh biết lổi do đâu

                      Comment


                      • #12
                        Mình chạy ko thấy báo lỗi.? :?
                        ----------------------------------------------------------------------------
                        Onemp Music Player : Light and powerful android music player

                        My APK : APK Extractor and MORE with friendly UI

                        Comment


                        • #13
                          mình biết đoạn code không có lổi, nhưng may mình cứ nhấn f5 là kh chạy được nó báo.......... bạn có biết cách nào kh giúp mình với

                          Comment


                          • #14
                            Originally posted by 11520158 View Post
                            mình biết đoạn code không có lổi, nhưng may mình cứ nhấn f5 là kh chạy được nó báo.......... bạn có biết cách nào kh giúp mình với
                            Mình chạy thử đoạn code và ko nhận được bất cứ lỗi nào cả. hi, bạn thử tạo lại 1 project khác và copy đoạn code đó rồi chạy thử coi sao.hi. chúc vui
                            ----------------------------------------------------------------------------
                            Onemp Music Player : Light and powerful android music player

                            My APK : APK Extractor and MORE with friendly UI

                            Comment


                            • #15
                              kh vui được bạn ơi, mình đã tạo rồi nhưng vẫn kh được,hjx

                              Comment

                              LHQC

                              Collapse
                              Working...
                              X