Like Tree12Likes
  • 2 Post By The Doctor
  • 4 Post By rags_to_riches
  • 4 Post By rogster001
  • 2 Post By Elysia

can anyone help me?

This is a discussion on can anyone help me? within the C++ Programming forums, part of the General Programming Boards category; Create two SORTED linked lists each having ten nodes…..the first list has a pointer called UNO to the first node ...

  1. #1
    Registered User
    Join Date
    May 2013
    Posts
    2

    can anyone help me?

    Create two SORTED linked lists each having ten nodes…..the first list has a pointer called UNO to the first node and the second list has a pointer called DUO to the first node. The nodes in each list contain two fields: LASTNAME and GPA


    Print out each sorted list after you create them…..then delete all nodes from the FIRST list whose GPA is above 3.0…and delete all nodes from the second list whose GPA is under 2.0. Print out both of these modified lists


    Finally..merge the REMAINING nodes from both lists into one list..headed by first BUT SORTED by LAST NAME. Print out the final list.

  2. #2
    Internet Superhero
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    964
    Sooo, you expect someone to make this for you and just hand it over?
    How I need a drink, alcoholic in nature, after the heavy lectures involving quantum mechanics.

  3. #3
    Time-Lord Victorious! The Doctor's Avatar
    Join Date
    Aug 2012
    Location
    Perth, Western Australia
    Posts
    50
    Policy on this forum is that the user should attempt their homework before asking for help.

    Please try to do it yourself, and if you have any questions, feel free to ask for help.

    We will not do it for you, as that will not help you in the long run.

    Good luck!
    Code:
    if (codeWorks( code) && !youCanDoSomethingBetter( code) )
    {
         beHappy();
    } else
    {
         fixCode( code);
    }

  4. #4
    Registered User
    Join Date
    May 2013
    Posts
    2
    hello
    see what I did
    but I need to know how can I merge both of them in one list by sorted last name

    Thanks
    srdg.cpp

  5. #5
    Time-Lord Victorious! The Doctor's Avatar
    Join Date
    Aug 2012
    Location
    Perth, Western Australia
    Posts
    50
    Code:
    #include <iostream> 
    #include <fstream> 
    #include <iomanip> 
    #include <string> 
     
    using namespace std; 
     
    void getdata(char name[], double &gpa) 
     
        { 
     
            cout << "Enter students name: "; 
     
            cin >> name;   
     
            cout << "Enter GPA: "; 
     
            cin >> gpa; 
     
        }//end getdata 
    class nodeType 
     
        { 
        public: 
     
            string name;         
     
            double gpa; 
     
            nodeType *next;         
     
        }; 
     
    int main() 
     
    { 
     
     
     
        nodeType *prior, *duo, *uno, *currentNode, *head; 
     
        char theName[4]; 
     
        double theGpa; 
     
        theGpa = 0.0; 
     
        for (int theList=1; theList<=2; theList++) 
     
        { 
     
            getdata(theName,theGpa); 
     
            currentNode = new nodeType; 
     
            currentNode->name = string(theName); 
     
            currentNode->gpa = theGpa; 
     
            currentNode->next = NULL; 
     
            head = currentNode; 
     
            prior = head; 
     
            for (int i=2;i<=10;i++) 
     
            { 
     
                getdata(theName,theGpa);     
     
                currentNode = new nodeType; 
     
                currentNode->name = string(theName); 
     
                currentNode->gpa = theGpa; 
     
            //sorting the list 
     
           if (currentNode->gpa > head->gpa)  
           { 
                  currentNode->next = head; 
                  head = currentNode; 
           } 
           else  
           { 
                prior = head; 
           
            while ((prior->next != NULL) && (prior->gpa) > (currentNode->gpa)) 
            { 
                if((prior->next->gpa)<(currentNode->gpa)) 
                { 
                    currentNode->next = prior->next; 
                    prior->next=currentNode; 
                } 
                  prior = prior->next;  
            } 
            if((prior->gpa)>(currentNode->gpa)) 
            { 
                currentNode->next = prior->next; 
                prior->next=currentNode; 
            } 
     
           } 
             
     
            }//end for loop i 
     
            if(theList == 1) 
            { 
     
                uno = head; 
                currentNode = head; 
     
            // output sorted list of uno 
     
            cout << "\nSorted List of List UNO " << endl << endl; 
            cout << setw(5) << "Student Name " << setw(10) << "GPA " << endl; 
     
            while(currentNode != NULL) 
     
            { 
                cout << setw(6) << currentNode->name << setw(16) << currentNode->gpa << endl; 
     
                cout << setiosflags(ios::fixed|ios::showpoint|ios::right); 
                cout << setprecision(2); 
     
                currentNode = currentNode->next; 
     
            }//end while 
     
            } // end if 
     
            else  
            { 
                duo = head; 
                currentNode = head; 
                         
            // output sorted list of duo 
     
            cout << "\nSorted List of List DUO " << endl << endl; 
            cout << setw(5) << "Student Name " << setw(10) << "GPA " << endl; 
     
            while(currentNode != NULL) 
     
            { 
                cout << setw(6) << currentNode->name << setw(16) << currentNode->gpa << endl; 
     
                cout << setiosflags(ios::fixed|ios::showpoint|ios::right); 
                cout << setprecision(2); 
     
                currentNode = currentNode->next; 
     
            }//end while 
     
            } // end else 
                 
     
        }//end for loop theList to process both lists 
     
     
        currentNode = uno; 
        prior = uno; 
     
        while (currentNode->gpa > 3.0) 
        { 
     
            currentNode = currentNode->next; 
            uno = currentNode; 
            prior = currentNode; 
        } 
            currentNode = currentNode->next; 
             
     
     
        while (currentNode->next != NULL)  
        { 
     
            if (currentNode->gpa > 3.0) 
            { 
     
                prior->next = currentNode->next; 
     
                currentNode = currentNode->next;  
     
            } 
            else 
            { 
     
            prior = currentNode; 
            currentNode = currentNode->next;  
     
            } 
         
        }//end for i 
     
        if (currentNode->gpa > 3.0) 
        { 
     
            prior->next = NULL; 
        } 
     
        currentNode = uno; 
     
        cout << "\nUNO List - All GPA's above 3.0 have been deleted " << endl << endl; 
        cout << setw(5) << "Student Name " << setw(10) << " GPA " << endl; 
     
            while(currentNode != NULL) 
     
            { 
     
                cout << setw(6) << currentNode->name << setw(16) << currentNode->gpa << endl; 
     
                cout << setiosflags(ios::fixed|ios::showpoint|ios::right); 
                cout << setprecision(2); 
     
                currentNode = currentNode->next; 
     
            }//end while 
     
     
        currentNode = duo; 
        prior = duo; 
     
        while (currentNode->gpa < 2.00)  
        { 
     
            currentNode = currentNode->next; 
            duo = currentNode; 
            prior = currentNode; 
        } 
            currentNode = currentNode->next; 
             
     
     
        while (currentNode->next != NULL) 
        { 
     
            if (currentNode->gpa < 2.5)  
            { 
     
                prior->next = currentNode->next; 
     
                currentNode = currentNode->next;  
     
            } 
            else 
            { 
     
            prior = currentNode; 
            currentNode = currentNode->next;  
     
            } 
     
            }//end for i 
     
        if (currentNode->gpa < 2.00) 
        { 
     
            prior->next = NULL; 
        } 
     
        currentNode = duo; 
     
        cout << "\nDUO List - All GPA's under 2.00 have been deleted" << endl << endl; 
        cout << setw(5) << "Student Name " << setw(10) << " GPA " << endl; 
         
     
            while(currentNode != NULL) 
     
            { 
     
                cout << setw(6) << currentNode->name << setw(16) << currentNode->gpa << endl; 
     
                cout << setiosflags(ios::fixed|ios::showpoint|ios::right); 
                cout << setprecision(2); 
                currentNode = currentNode->next; 
     
            }//end while 
        int xx; 
        cout <<" to end press xx"; 
        cin >> xx; 
             
        return 0; 
    }//end main
    There's his code, put up on the forums.
    Salem and rags_to_riches like this.
    Code:
    if (codeWorks( code) && !youCanDoSomethingBetter( code) )
    {
         beHappy();
    } else
    {
         fixCode( code);
    }

  6. #6
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,652
    Let me correct that for The Doctor. Here is the user's code he copied and pasted from elsewhere.

  7. #7
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,438
    Here is the user's code he copied and pasted from elsewhere.
    sigh - it was so on the cards. Why cant people just try properly themselves? It does not take much intelligence to realise you are going to have at least as much, - and probably more difficulty in hacking a large chunk of someone else's code, - which you have no comprehesion of - Than if you actually knuckled down and tried! Plus the bonus is - you might actually learn !
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  8. #8
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,791
    Well, the code is complete and utter garbage anyway, so you're better of doing it from scratch anyway if you want to learn.
    And if you don't want to learn, well... then you've come to the wrong place.
    Salem and The Doctor like this.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #9
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,308
    Here goes another case of the stages of attempting to get someone else to do your work for you:
    1. Try to get it for free.
    2. Rip off others work and pretend that was their effort.
    3. Denial. E.g. I didn't want to post my own code, but this code is similar.
    4. Hurling abuse at those who wont help.
    5. Begging others to do it for them.
    6. Offering money to do it for them.
    ...
    N. Handing in the plagurised work and claiming they misunderstood the question.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  10. #10
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,673
    Pretty much everything worth saying has been said, so time to draw this to a close.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21