Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
//Q2.4) WAP to implement a linked list, update data at any position, update a value and then print the linked list. #include
#include
using namespace std; struct node{ int data; node* next; void setData(int d){ data=d; next=NULL; } }; void InsertAtHead(node* &head,int data){ node* newNode=(node*)malloc(sizeof(node)); newNode->setData(data); newNode->next=head; head=newNode; } void InsertAtTail(node* &tail,int data){ node* newNode=(node*)malloc(sizeof(node)); newNode->setData(data); tail->next=newNode; tail=newNode; } void UpdateAtPosition(node* &head,int position,int newValue){ node* temp=head; int nodeNumber=1; while(nodeNumber
next; nodeNumber++; } temp->data=newValue; } void UpdateTheValue(node* head,int oldValue,int newValue){ node* temp=head; while(temp!=NULL){ if(temp->data==oldValue){ temp->data=newValue; } temp=temp->next; } } void PrintLinkedList(node* &head){ node* temp=head; while(temp!=NULL){ cout<
data<<" "; temp=temp->next; } cout<
setData(1); node* tail=head; InsertAtHead(head,2); InsertAtTail(tail,4); InsertAtTail(tail,6); cout<<"Before Position Updation: "; PrintLinkedList(head); UpdateAtPosition(head,1,6); cout<<"After Position Updation: "; PrintLinkedList(head); cout<
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)