Answer to Question #225857 in C++ for Dhruvi

Question #225857
Write a C++ data structure program that will perform following operations on
linked list.
 Insert two nodes
 Display using loop
Node structure
1 integer value
1 float value
1 string value
1 address of next node
example
Rollno : 1
Name: Roy
Marks: 76.89
Next: address of the next node
1
Expert's answer
2021-08-13T16:14:02-0400
#include <iostream>
#include <cstdlib>
using namespace std;
struct Node {
   float data;
   struct Node *next;
};
struct Node* head = NULL;
void insert(float new_data) {
   struct Node* new_node = (struct Node*) malloc(sizeof(struct Node));
   new_node->data = new_data;
   new_node->next = head;
   head = new_node;
}
void output() {
   struct Node* ptr;
   ptr = head;
   while (ptr != NULL) {
      cout<< ptr->data <<" "<<"\n";
      ptr = ptr->next;
   }
}
int main() {
   insert(76.89);
   insert(1);
   cout<<"Here is the link list created \n";
   output(); 
   cout<<"Roy ";
}

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