Answer to Question #220968 in C++ for Vasanth

Question #220968
A man goes for shopping to buy vegetables. He picks up the basket and goes to the shelf of vegetables. The tray can hold up to 10kg only. So he carefully picks up the vegetables needed for one week and fills his basket. When he reaches the end of shelf, he finds he had filled only 8.5 kg. So he decides to refill with some more vegetables for his need. Write a C program to implement the refilling process using linked list.
1
Expert's answer
2021-07-28T03:00:00-0400
#include <iostream>
using namespace std;
 
class Node {
public:
    int d;
    Node* nt;
};
void printList(Node* n)
{
    while (n != NULL) {
        cout << n->d << " ";
        n = n->nt;
    }
}
 
int main()
{
    Node* h = NULL;
    Node* s = NULL;
    Node* t = NULL;
 
    h = new Node();
    s = new Node();
    t = new Node();
 
    h->d = 1; 
    h->nt = s; 
 
    s->d = 2; 
    s->nt = t;
 
    t->d = 3; 
    t->nt = NULL;
 
    printList(h);
 
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS