Question

PLEASE FILL THE CODE ACCORDINGY AND THE REQUIRED OUTPUT IS GIVEN BELOW ALONG WITH THE INPUT...

PLEASE FILL THE CODE ACCORDINGY AND THE REQUIRED OUTPUT IS GIVEN BELOW ALONG WITH THE INPUT

Problem:
The following function, buildListForward, builds a linked list in a forward manner and
returns the pointer of the built list:
Q1: The bulidListForward function to create a linked List structure with the keyboard
input( cin >> num). Change this function to receive the values stored in the array from the
main function( use int type pointer variable).
eg. nodeType* buildListForward(int *arrayPrt, int Size)
Q2: Implement main function to call bulidListForward with an array type actual parameter
that contains node information 2, 15, 8, 24, 34.
Q3: Declare a struct named nodeType which contains two members
info and *link;
Q4: Inside of the function buildListForward,
change while loop to for loop to be able to get node information from the array and put
this node information to newNode.
Q5: At the main function, print out node information by Traversing the Linked List that we
have created at the main function and print out node information as follows:
Input
int Size_Array = 5;
int ArrayInfo[5] = { 2, 5, 8, 24, 34 };
Output
& address of curr pointer 0x125cc20
& address of info: 0x125cc20 INFO: 2 LINK 0x125cc40
& address of info: 0x125cc40 INFO: 5 LINK 0x125cc60
& address of info: 0x125cc60 INFO: 8 LINK 0x125cc80
& address of info: 0x125cc80 INFO: 24 LINK 0x125cca0
& address of info: 0x125cca0 INFO: 34 LINK 0


#include<iostream>
using namespace std;
struct nodeType{
int info;
struct nodeType* link;
};
//nodeType* buildListForward(int*, int);
nodeType* buildListForward()
{
nodeType *first, *newNode, *last;
int num;
cout << "Enter a first of interges." << endl;
cin >> num;
first = NULL;
while (num != -999)
{
newNode = new nodeType;
newNode->info = num;
newNode->link = NULL;
if (first == NULL)
{
first = newNode;
last = newNode;
} else
{
last->link = newNode;
last = newNode;
}
cout << "list of integers ending with -999." << endl;
cin >> num;
} //end while
return first;
} //end buildListForward
int main ( ) {
nodeType *head, *curr;
head = buildListForward();
curr = head;
while( curr!=NULL)
{
cout << "Current Node " << curr->info;
curr = curr->link;
}
return 0;
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream>
using namespace std;
struct nodeType{
int info;
struct nodeType* link;
};
nodeType* buildListForward(int *arrayPrt, int Size)
{
nodeType *first, *newNode, *last;
first = NULL;
for(int i=0;i<Size;i++)
{
newNode = new nodeType;
newNode->info = arrayPrt[i];
newNode->link = NULL;
if (first == NULL)
{
first = newNode;
last = newNode;
} else
{
last->link = newNode;
last = newNode;
}
} //end for
return first;
  
}
int main ( ) {
int Size_Array = 5;
int ArrayInfo[5] = { 2, 5, 8, 24, 34 };
nodeType *head, *curr;
head = buildListForward(ArrayInfo,Size_Array);
curr = head;
cout << "& address of curr pointer " << curr << endl;
while( curr!=NULL)
{
cout << "& address of info: " << curr << " INFO: " << curr->info << " LINK" << curr->link << endl;
curr = curr->link;
}
return 0;
}

output:

$g++ -o main *.cpp
$main
& address of curr pointer 0x2173010
& address of info: 0x2173010 INFO: 2 LINK0x2173030
& address of info: 0x2173030 INFO: 5 LINK0x2173050
& address of info: 0x2173050 INFO: 8 LINK0x2173070
& address of info: 0x2173070 INFO: 24 LINK0x2173090
& address of info: 0x2173090 INFO: 34 LINK0

% Execute | Embedm main.cppSTDIN I.li Result S struct nodeType link; $g++ 丰.cpp -o mai n main 7 nodeType buildListForward(int

Add a comment
Know the answer?
Add Answer to:
PLEASE FILL THE CODE ACCORDINGY AND THE REQUIRED OUTPUT IS GIVEN BELOW ALONG WITH THE INPUT...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I have a problem with merging the two linked lists together. In the function AscendMerge, I...

    I have a problem with merging the two linked lists together. In the function AscendMerge, I am trying to compare the values of each node in the two lists and output them into one list in ascended order. Everything works except for the one function. Can someone tell me what im doing wrong, when I run it it skips over values. #include <iostream> #include <cassert> using namespace std; struct nodeType {    int info;    nodeType *link;    nodeType *current;...

  • How would you get this lab to work with the numbers 37 14 68 47, the...

    How would you get this lab to work with the numbers 37 14 68 47, the book we are using is Data structures using C++ by D.S. Malik. Please I need help? Just keeps repeating the same question. Code: #include <iostream> #include <cstdlib> using namespace std; struct nodeType { int info; nodeType *link; }; void createList(nodeType*& first, nodeType*& last); void printList(nodeType*& first); void insertFront(nodeType*& first); void insertBack(nodeType*& last); void deleteFirst(nodeType*& first); void deleteLast(nodeType*& last, nodeType* first); int main() { nodeType...

  • C++ pointers and linked lists 1. Declare an integer pointer variable intPointer. Initialize it to point...

    C++ pointers and linked lists 1. Declare an integer pointer variable intPointer. Initialize it to point to an int variable named someInt. Assign the value 451 to someInt and output (cout) the variable someInt and output (cout) the value pointed to by intPointer. Write an assignment statement that indirectly stores 900 into the value pointed to by intPointer. Output (cout) the value pointed to by intPointer and output (cout) the variable someInt, 2. Declare a pointer variable charArrPointer and initialize...

  • Consider the following C++ statements: struct node Type int info; node Type *link; nodeType *head, *p,...

    Consider the following C++ statements: struct node Type int info; node Type *link; nodeType *head, *p, q, *newNode; newNode = new node Type; 1. Write C++ statement to store 50 in the info field of the newNode. 2. Write C++ statement to set the link field of the newNode to NULL. 3. Write C++ statement to make head pointer points to newNode. 4. Write C++ statement to delete the first node in the linked list. (the first an the only...

  • This is the creatList and printList function #include <iostream> #include <fstream> using namespace std; struct nodeType...

    This is the creatList and printList function #include <iostream> #include <fstream> using namespace std; struct nodeType {    int info;    nodeType *link;    nodeType *next;    double value; }; void createList(nodeType*& first, nodeType*& last, ifstream& inf); void printList(nodeType* first); int main() {    nodeType *first, *last;    int num;    ifstream infile;    infile.open("InputIntegers.txt");    createList(first, last, infile);    printList(first);    infile.close();    system("pause");    return 0; } void createList(nodeType*& first, nodeType*& last, ifstream& infile) {    int number;...

  • #include <iostream> using namespace std; struct ListNode { float value; ListNode *next; }; ...

    #include <iostream> using namespace std; struct ListNode { float value; ListNode *next; }; ListNode *head; class LinkedList { public: int insertNode(float num); void deleteNode(float num); void destroyList(); void displayList(); LinkedList(void) {head = NULL;} ~LinkedList(void) {destroyList();} }; int LinkedList::insertNode(float num) { struct ListNode *newNode, *nodePtr = head, *prevNodePtr = NULL; newNode = new ListNode; if(newNode == NULL) { cout << "Error allocating memory for new list member!\n"; return 1; } newNode->value = num; newNode->next = NULL; if(head==NULL) { cout << "List...

  • Please fill in this code to reverse a linked list: (written in C/C++) #include #include #include...

    Please fill in this code to reverse a linked list: (written in C/C++) #include #include #include using namespace std; /* Link list node */ struct Node { int data; // your code here }; /* Function to reverse the linked list */ static void reverse(struct Node** head_ref) { // your code here } /* Function to push a node */ void push(struct Node** head_ref, int new_data) { // your code here } /* Function to print linked list */ void...

  • Double linked list implementation of PutItem function. How to fix my code to get desired output b...

    Double linked list implementation of PutItem function. How to fix my code to get desired output below: Output: 2 5 8 #ifndef ITEMTYPE_H #define ITEMTYPE_H enum RelationType { LESS, GREATER, EQUAL}; class ItemType { public:     ItemType();     void setValue(int newValue);     int getValue() const;     RelationType ComparedTo(ItemType newItem); private:     int value; }; #endif // ITEMTYPE_H // ItemType.cpp #include "ItemType.h" ItemType::ItemType() {     value = 0; } void ItemType::setValue(int newValue) {     value = newValue; } int ItemType::getValue() const {     return value; } RelationType ItemType::ComparedTo(ItemType newItem)...

  • can someone please double check my code here are the requirements please help me fulfill the...

    can someone please double check my code here are the requirements please help me fulfill the requirements Using the material in the textbook (NumberList) as a sample, design your own dynamic linked list class (using pointers) to hold a series of capital letters. The class should have the following member functions: append, insert (at a specific position, return -1 if that position doesn't exist), delete (at a specific position, return -1 if that position doesn't exist), print, reverse (which rearranges...

  • Introduction In this lab, you are supposed to implement a graph class with the data structure...

    Introduction In this lab, you are supposed to implement a graph class with the data structure implemented before like linked list and queue. graph The class graph contains three member variables: linkedList *adjacentVertices; //an array of linked list. For a vertice i, adjacentVertices[i] stores the linked list that contains all other vertices connected to vertice i. int numVertices; //The number of vertices in the graph. int maxNumVertices; //The maximum number of vertices the graph can hold. Following public methods are...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT