Question: 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
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
