Write a program to multiply every element of the linked list with 10
#include<iostream>
using namespace std;
class Node{
public:
int data;
Node * next;
};
void push(Node** head, int data)
{
Node* node = new Node();
node->data = data;
node->next = (*head);
(*head) = node;
}
void display(Node * node){
while(node != NULL){
cout<<node->data<<" ";
node = node->next;
}
cout<<endl;
}
void multiply(Node *node){
while(node !=NULL){
cout<<node->data * 10<<" ";
node = node->next;
}
}
int main(){
Node *list = NULL;
push(&list,1);
push(&list,3);
push(&list,4);
push(&list,5);
cout<<"The elements of the linked list are: ";
display(list);
cout<<"After multiplying every element in the linked list by 10: ";
multiply(list);
}
Comments
Leave a comment