Answered step by step
Verified Expert Solution
Question
1 Approved Answer
given the implementation of a singly ( linear ) linked list of character elements Please modify the code as follows. Add a function named swapLastWithFirst
given the implementation of a singly linear linked list of character elements Please modify the code as follows. Add a function named "swapLastWithFirst" which swaps the first node with the last node. Thereafter, the "main" function should call "swapLastWithFirst" and then call "printList"
#include
using namespace std;
struct Node
char data;
struct Node next;
;
struct Node headNULL;
void printList
Node curr head;
whilecurr NULL
cout currdata ;
curr currnext;
cout endl;
void insertFirstchar data
Node newNode new Node;
newNodedata data;
newNodenext NULL;
ifhead NULL
head newNode;
else
newNodenext head;
head newNode;
void insertLastchar data
Node newNode new Node;
newNodedata data;
newNodenext NULL;
ifhead NULL
head newNode;
else
Node curr head;
whilecurrnext NULL
curr currnext;
currnext newNode;
void insertAtPoschar data, int pos
Node newNode new Node;
newNodedata data;
newNodenext NULL;
int curPos ;
ifhead NULL
head newNode;
else
Node curr head;
Node prev;
whilecurPos pos && currnext NULL
prevcurr;
curr currnext;
curPos;
prevnext newNode;
newNodenext curr;
void deleteAtPosint pos
Node curr head;
int curPos ;
if head NULL
ifpos
head currnext;
delete curr;
else
Node prev;
whilecurPos pos && currnext NULL
prevcurr;
curr currnext;
curPos;
prevnext currnext;
delete curr;
int searchchar value
int pos ;
Node curr head;
whilecurr NULL
ifcurrdata value
return pos;
pos;
curr currnext;
return ;
int main
cout "Hello World!
;
insertFirsta;
insertFirstb;
insertFirstc;
insertFirstd;
printList;
insertLaste;
insertLastf;
insertAtPosg;
printList;
deleteAtPos;
printList;
deleteAtPos;
printList;
int pos searche;
cout pos endl;
pos searchf;
cout pos endl;
return ;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started