samedi 28 avril 2018

How do I create three Nodes from the user's input

I'm having with linked list assignment. This my computer class assignment. And This is my very first time learning list. It's quite difficult for me understand this. Can some please help me with this assignment?

here is what my professor said what I need to do:

In main, prompt the user for three contacts.

Create three ContactNodes from the user's input Use the nodes to build a linked list use the insertAfter function to link each node together

Here is main:

#include <iostream>
#include "ContactNode.h"

using namespace std;

int main()
{
    ContactNode* headNode = nullptr;
    ContactNode* node1 = nullptr;
    ContactNode* node2 = nullptr;
    ContactNode* node3 = nullptr;
    ContactNode* currObj = nullptr;

    string name1;
    string name2;
    string name3;
    string phoneNum1;
    string phoneNum2;
    string phoneNum3;

    cout << "Enter name: " << endl;
    getline(cin, name1);

    cout << "Enter phone number: " << endl;
    getline(cin, phoneNum1);



    currObj = headNode;
    while (currObj != NULL)
    {
        currObj->printContactNode();
        currObj = currObj->getNext();
    }

}

Aucun commentaire:

Enregistrer un commentaire