1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

linear register

Discussion in 'C' started by logistic, Jun 6, 2007.

  1. logistic

    logistic New Member

    Joined:
    Jun 6, 2007
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    Hi, i'm sorry for bothering you, i wanted to arrange numbers (ascending), i tought everything is ok, but... where's the problem? Thanks...

    Code:
    void sort(){
    elementi *temp = first, *next, *t1, *t2;
    
    for(next = temp->next; next !=NULL; next = temp->next){
    next=temp->next;
    if(temp->value > next->value) {
    
    if(next!=last){
    t1=temp;
    t2=next;
    t1->next=next->next;
    temp=t2;
    next=t1;}
    
    else { t1=temp;
    t1->next=NULL;
    t1=last;
    temp=temp->next;
    temp->next=t1;
    }}
    
    else {  
    temp = temp->next;
    }}
    };
    
     
  2. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    You're supposed to tell us what you expect to happen and how that's failing to happen. You are also supposed to tell us what things like "elementi" are. You're looking at your code and can't figure it out, but you want us to do it with guesses. Nuh uh.
     
  3. logistic

    logistic New Member

    Joined:
    Jun 6, 2007
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    My CODE looks like that, but, for example i enter values 1, 5, 4, 10 -> i suppose to see out -> 1, 4, 5 10, but i see just -> 1, 5, 10 :confused:
    Code:
    class klase {
          struct elementi {
                          int value;            //value of node
                          elementi *next;
                          };
          elementi *current, *last, *first;
          public :
                 klase(){last = current = first = NULL;}                        
                 ~klase() { izdzest(); };
               
    void sort(){
         elementi *temp = first, *next, *t1, *t2;
    
         for(next = temp->next; next !=NULL; next = temp->next){
                  next=temp->next;
              if(temp->value > next->value) {
    
              if(next!=last){
                t1=temp;
                t2=next;
                t1->next=next->next;
                temp=t2;
                next=t1;}
    
             else { t1=temp;
                 t1->next=NULL;
                 t1=last;
                 temp=temp->next;
                 temp->next=t1; }}
             else {  
               temp = temp->next; }}
    }; 
     

Share This Page