SlideShare a Scribd company logo
1 of 8
Download to read offline
#include
struct node
{
char value;
struct node *next;
};
class StringOfNode
{
struct node * head;
public:
StringOfNode()
{
head=NULL;
}
int size()
{
struct node *p=head;
int count=1;
while(p)
{
count++;
p=p->next;
}
return count;
}
struct node * begin()
{
return head;
}
char &operator[](int index)
{
int i=0;
struct node *p=head;
while(index!=i)
{
p=p->next;
i++;
}
return p->value;
}
void insertFront(char valuee)
{
struct node * temp=(struct node *)malloc(sizeof(struct node));
temp->value=valuee;
temp->next=NULL;
if(head==NULL)
head=temp;
else
{
temp->next=head;
head=temp;
}
}
void insert(char valuee, int pos)
{
struct node *p=head;
struct node * temp=(struct node *)malloc(sizeof(struct node));
temp->value=valuee;
temp->next=NULL;
int i=0;
if(p==NULL)
{
head=temp;
}
else
{
while(i!=pos-1)
{
p=p->next;
i++;
}
temp->next=p->next;
p->next=temp;
}
}
void insertBack(char valuee)
{
struct node *p=head;
struct node * temp=(struct node *)malloc(sizeof(struct node));
temp->value=valuee;
temp->next=NULL;
if(p==NULL)
{
head=temp;
}
else
{
while(p->next!=NULL)
p=p->next;
p->next=temp;
}
}
void print()
{
struct node *p=head;
while(p)
{
std::cout<value<<" ";
p=p->next;
}
}
StringOfNode operator+(const StringOfNode& b)
{
StringOfNode *S;
struct node *p=head;
while(p->next!=NULL)
p=p->next;
p->next=S->begin();
}
};
int main()
{
StringOfNode *p1=new StringOfNode;
p1->insertBack('b');
p1->insertBack('c');
p1->insertBack('e');
p1->insert('d',2);
p1->insertFront('a');
p1->print();
system("pause");
return 0;
}
Solution
#include
struct node
{
char value;
struct node *next;
};
class StringOfNode
{
struct node * head;
public:
StringOfNode()
{
head=NULL;
}
int size()
{
struct node *p=head;
int count=1;
while(p)
{
count++;
p=p->next;
}
return count;
}
struct node * begin()
{
return head;
}
char &operator[](int index)
{
int i=0;
struct node *p=head;
while(index!=i)
{
p=p->next;
i++;
}
return p->value;
}
void insertFront(char valuee)
{
struct node * temp=(struct node *)malloc(sizeof(struct node));
temp->value=valuee;
temp->next=NULL;
if(head==NULL)
head=temp;
else
{
temp->next=head;
head=temp;
}
}
void insert(char valuee, int pos)
{
struct node *p=head;
struct node * temp=(struct node *)malloc(sizeof(struct node));
temp->value=valuee;
temp->next=NULL;
int i=0;
if(p==NULL)
{
head=temp;
}
else
{
while(i!=pos-1)
{
p=p->next;
i++;
}
temp->next=p->next;
p->next=temp;
}
}
void insertBack(char valuee)
{
struct node *p=head;
struct node * temp=(struct node *)malloc(sizeof(struct node));
temp->value=valuee;
temp->next=NULL;
if(p==NULL)
{
head=temp;
}
else
{
while(p->next!=NULL)
p=p->next;
p->next=temp;
}
}
void print()
{
struct node *p=head;
while(p)
{
std::cout<value<<" ";
p=p->next;
}
}
StringOfNode operator+(const StringOfNode& b)
{
StringOfNode *S;
struct node *p=head;
while(p->next!=NULL)
p=p->next;
p->next=S->begin();
}
};
int main()
{
StringOfNode *p1=new StringOfNode;
p1->insertBack('b');
p1->insertBack('c');
p1->insertBack('e');
p1->insert('d',2);
p1->insertFront('a');
p1->print();
system("pause");
return 0;
}

More Related Content

Similar to #includeiostream struct node {    char value;    struct no.pdf

Doublylinklist
DoublylinklistDoublylinklist
Doublylinklist
ritu1806
 
C++ Program to Implement Singly Linked List #includeiostream.pdf
 C++ Program to Implement Singly Linked List #includeiostream.pdf C++ Program to Implement Singly Linked List #includeiostream.pdf
C++ Program to Implement Singly Linked List #includeiostream.pdf
angelsfashion1
 
I need to fill-in TODOs in .cpp file and in .h file Could some.pdf
I need to fill-in TODOs in .cpp file and in .h file Could some.pdfI need to fill-in TODOs in .cpp file and in .h file Could some.pdf
I need to fill-in TODOs in .cpp file and in .h file Could some.pdf
forladies
 
implement the ListLinked ADT (the declaration is given in ListLinked.pdf
implement the ListLinked ADT (the declaration is given in ListLinked.pdfimplement the ListLinked ADT (the declaration is given in ListLinked.pdf
implement the ListLinked ADT (the declaration is given in ListLinked.pdf
FOREVERPRODUCTCHD
 
Double linked list header file below for FYI#include iostream.pdf
Double linked list header file below for FYI#include iostream.pdfDouble linked list header file below for FYI#include iostream.pdf
Double linked list header file below for FYI#include iostream.pdf
facevenky
 
In C++ I need help with this method that Im trying to write fillLi.pdf
In C++ I need help with this method that Im trying to write fillLi.pdfIn C++ I need help with this method that Im trying to write fillLi.pdf
In C++ I need help with this method that Im trying to write fillLi.pdf
fantoosh1
 
–PLS write program in c++Recursive Linked List OperationsWrite a.pdf
–PLS write program in c++Recursive Linked List OperationsWrite a.pdf–PLS write program in c++Recursive Linked List OperationsWrite a.pdf
–PLS write program in c++Recursive Linked List OperationsWrite a.pdf
pasqualealvarez467
 
Code#include stdio.h #includemalloc.h struct node {  .pdf
Code#include stdio.h #includemalloc.h struct node {  .pdfCode#include stdio.h #includemalloc.h struct node {  .pdf
Code#include stdio.h #includemalloc.h struct node {  .pdf
brijmote
 
#includeiostream#includecstdio#includecstdlibusing names.pdf
#includeiostream#includecstdio#includecstdlibusing names.pdf#includeiostream#includecstdio#includecstdlibusing names.pdf
#includeiostream#includecstdio#includecstdlibusing names.pdf
KUNALHARCHANDANI1
 

Similar to #includeiostream struct node {    char value;    struct no.pdf (20)

Doublylinklist
DoublylinklistDoublylinklist
Doublylinklist
 
C++ Program to Implement Singly Linked List #includeiostream.pdf
 C++ Program to Implement Singly Linked List #includeiostream.pdf C++ Program to Implement Singly Linked List #includeiostream.pdf
C++ Program to Implement Singly Linked List #includeiostream.pdf
 
Linked lists
Linked listsLinked lists
Linked lists
 
Singly linked list program in data structure - Vtech
Singly linked list program in data structure - VtechSingly linked list program in data structure - Vtech
Singly linked list program in data structure - Vtech
 
Ds 2 cycle
Ds 2 cycleDs 2 cycle
Ds 2 cycle
 
I need to fill-in TODOs in .cpp file and in .h file Could some.pdf
I need to fill-in TODOs in .cpp file and in .h file Could some.pdfI need to fill-in TODOs in .cpp file and in .h file Could some.pdf
I need to fill-in TODOs in .cpp file and in .h file Could some.pdf
 
i nsert+in+ link list
i nsert+in+ link listi nsert+in+ link list
i nsert+in+ link list
 
Linked list imp of list
Linked list imp of listLinked list imp of list
Linked list imp of list
 
Singly linked list.pptx
Singly linked list.pptxSingly linked list.pptx
Singly linked list.pptx
 
DSA(1).pptx
DSA(1).pptxDSA(1).pptx
DSA(1).pptx
 
C++Write a function void headEnqueue(Queue q, int key) which enqu.pdf
C++Write a function void headEnqueue(Queue q, int key) which enqu.pdfC++Write a function void headEnqueue(Queue q, int key) which enqu.pdf
C++Write a function void headEnqueue(Queue q, int key) which enqu.pdf
 
implement the ListLinked ADT (the declaration is given in ListLinked.pdf
implement the ListLinked ADT (the declaration is given in ListLinked.pdfimplement the ListLinked ADT (the declaration is given in ListLinked.pdf
implement the ListLinked ADT (the declaration is given in ListLinked.pdf
 
Double linked list header file below for FYI#include iostream.pdf
Double linked list header file below for FYI#include iostream.pdfDouble linked list header file below for FYI#include iostream.pdf
Double linked list header file below for FYI#include iostream.pdf
 
In C++ I need help with this method that Im trying to write fillLi.pdf
In C++ I need help with this method that Im trying to write fillLi.pdfIn C++ I need help with this method that Im trying to write fillLi.pdf
In C++ I need help with this method that Im trying to write fillLi.pdf
 
–PLS write program in c++Recursive Linked List OperationsWrite a.pdf
–PLS write program in c++Recursive Linked List OperationsWrite a.pdf–PLS write program in c++Recursive Linked List OperationsWrite a.pdf
–PLS write program in c++Recursive Linked List OperationsWrite a.pdf
 
C code on linked list #include stdio.h #include stdlib.h.pdf
 C code on linked list #include stdio.h #include stdlib.h.pdf C code on linked list #include stdio.h #include stdlib.h.pdf
C code on linked list #include stdio.h #include stdlib.h.pdf
 
Code#include stdio.h #includemalloc.h struct node {  .pdf
Code#include stdio.h #includemalloc.h struct node {  .pdfCode#include stdio.h #includemalloc.h struct node {  .pdf
Code#include stdio.h #includemalloc.h struct node {  .pdf
 
Doubly linklist
Doubly linklistDoubly linklist
Doubly linklist
 
C program
C programC program
C program
 
#includeiostream#includecstdio#includecstdlibusing names.pdf
#includeiostream#includecstdio#includecstdlibusing names.pdf#includeiostream#includecstdio#includecstdlibusing names.pdf
#includeiostream#includecstdio#includecstdlibusing names.pdf
 

More from ankitmobileshop235

Vi may be a powerful text editor enclosed with most UNIX systems, ev.pdf
Vi may be a powerful text editor enclosed with most UNIX systems, ev.pdfVi may be a powerful text editor enclosed with most UNIX systems, ev.pdf
Vi may be a powerful text editor enclosed with most UNIX systems, ev.pdf
ankitmobileshop235
 
U.S management is trained to provide the executives their own career.pdf
U.S management is trained to provide the executives their own career.pdfU.S management is trained to provide the executives their own career.pdf
U.S management is trained to provide the executives their own career.pdf
ankitmobileshop235
 
There are many operating systemsReal-Time Operating SystemReal-t.pdf
There are many operating systemsReal-Time Operating SystemReal-t.pdfThere are many operating systemsReal-Time Operating SystemReal-t.pdf
There are many operating systemsReal-Time Operating SystemReal-t.pdf
ankitmobileshop235
 
The three major forms of business organizations are1. Sole Propri.pdf
The three major forms of business organizations are1. Sole Propri.pdfThe three major forms of business organizations are1. Sole Propri.pdf
The three major forms of business organizations are1. Sole Propri.pdf
ankitmobileshop235
 
The EVA metric effectively measures the amount of shareholder wealth.pdf
The EVA metric effectively measures the amount of shareholder wealth.pdfThe EVA metric effectively measures the amount of shareholder wealth.pdf
The EVA metric effectively measures the amount of shareholder wealth.pdf
ankitmobileshop235
 
Part ATay-Sachs disease is an autosomal recessive disorder, so, o.pdf
Part ATay-Sachs disease is an autosomal recessive disorder, so, o.pdfPart ATay-Sachs disease is an autosomal recessive disorder, so, o.pdf
Part ATay-Sachs disease is an autosomal recessive disorder, so, o.pdf
ankitmobileshop235
 
Information is a valuable asset that can make or break your business.pdf
Information is a valuable asset that can make or break your business.pdfInformation is a valuable asset that can make or break your business.pdf
Information is a valuable asset that can make or break your business.pdf
ankitmobileshop235
 

More from ankitmobileshop235 (20)

- You have to overcome the ionic forces of the CsI, the hydrogen bon.pdf
- You have to overcome the ionic forces of the CsI, the hydrogen bon.pdf- You have to overcome the ionic forces of the CsI, the hydrogen bon.pdf
- You have to overcome the ionic forces of the CsI, the hydrogen bon.pdf
 
Two sp3 orbitals are filled by lone electron pair.pdf
                     Two sp3 orbitals are filled by lone electron pair.pdf                     Two sp3 orbitals are filled by lone electron pair.pdf
Two sp3 orbitals are filled by lone electron pair.pdf
 
X-Intercept is the value of x where cross x axis. Another name is .pdf
X-Intercept is the value of x where cross x axis. Another name is .pdfX-Intercept is the value of x where cross x axis. Another name is .pdf
X-Intercept is the value of x where cross x axis. Another name is .pdf
 
whether or not the viruses is not used to classify viruses.Vir.pdf
whether or not the viruses is not used to classify viruses.Vir.pdfwhether or not the viruses is not used to classify viruses.Vir.pdf
whether or not the viruses is not used to classify viruses.Vir.pdf
 
Vi may be a powerful text editor enclosed with most UNIX systems, ev.pdf
Vi may be a powerful text editor enclosed with most UNIX systems, ev.pdfVi may be a powerful text editor enclosed with most UNIX systems, ev.pdf
Vi may be a powerful text editor enclosed with most UNIX systems, ev.pdf
 
U.S management is trained to provide the executives their own career.pdf
U.S management is trained to provide the executives their own career.pdfU.S management is trained to provide the executives their own career.pdf
U.S management is trained to provide the executives their own career.pdf
 
There are many operating systemsReal-Time Operating SystemReal-t.pdf
There are many operating systemsReal-Time Operating SystemReal-t.pdfThere are many operating systemsReal-Time Operating SystemReal-t.pdf
There are many operating systemsReal-Time Operating SystemReal-t.pdf
 
The three major forms of business organizations are1. Sole Propri.pdf
The three major forms of business organizations are1. Sole Propri.pdfThe three major forms of business organizations are1. Sole Propri.pdf
The three major forms of business organizations are1. Sole Propri.pdf
 
the OSI model is an idea. it is abstract it has no value without imp.pdf
the OSI model is an idea. it is abstract it has no value without imp.pdfthe OSI model is an idea. it is abstract it has no value without imp.pdf
the OSI model is an idea. it is abstract it has no value without imp.pdf
 
The EVA metric effectively measures the amount of shareholder wealth.pdf
The EVA metric effectively measures the amount of shareholder wealth.pdfThe EVA metric effectively measures the amount of shareholder wealth.pdf
The EVA metric effectively measures the amount of shareholder wealth.pdf
 
Reflection about the centre of the pentagon is not its symmetric and.pdf
Reflection about the centre of the pentagon is not its symmetric and.pdfReflection about the centre of the pentagon is not its symmetric and.pdf
Reflection about the centre of the pentagon is not its symmetric and.pdf
 
Question not visible. Please state again.SolutionQuestion not .pdf
Question not visible. Please state again.SolutionQuestion not .pdfQuestion not visible. Please state again.SolutionQuestion not .pdf
Question not visible. Please state again.SolutionQuestion not .pdf
 
Per my quiz, it was also D) formation of the carbocatio or bromonium.pdf
Per my quiz, it was also D) formation of the carbocatio or bromonium.pdfPer my quiz, it was also D) formation of the carbocatio or bromonium.pdf
Per my quiz, it was also D) formation of the carbocatio or bromonium.pdf
 
Part ATay-Sachs disease is an autosomal recessive disorder, so, o.pdf
Part ATay-Sachs disease is an autosomal recessive disorder, so, o.pdfPart ATay-Sachs disease is an autosomal recessive disorder, so, o.pdf
Part ATay-Sachs disease is an autosomal recessive disorder, so, o.pdf
 
null is a subset of every setTrueSolutionnull is a sub.pdf
null is a subset of every setTrueSolutionnull is a sub.pdfnull is a subset of every setTrueSolutionnull is a sub.pdf
null is a subset of every setTrueSolutionnull is a sub.pdf
 
LiOH Sol.pdf
                     LiOH                                      Sol.pdf                     LiOH                                      Sol.pdf
LiOH Sol.pdf
 
Information is a valuable asset that can make or break your business.pdf
Information is a valuable asset that can make or break your business.pdfInformation is a valuable asset that can make or break your business.pdf
Information is a valuable asset that can make or break your business.pdf
 
Ho there is no relationship between the age of the individual and t.pdf
Ho there is no relationship between the age of the individual and t.pdfHo there is no relationship between the age of the individual and t.pdf
Ho there is no relationship between the age of the individual and t.pdf
 
H2SO3 - H2O = SO2The oxide is sulfur dioxide SO2SolutionH2.pdf
H2SO3 - H2O = SO2The oxide is sulfur dioxide SO2SolutionH2.pdfH2SO3 - H2O = SO2The oxide is sulfur dioxide SO2SolutionH2.pdf
H2SO3 - H2O = SO2The oxide is sulfur dioxide SO2SolutionH2.pdf
 
First of all we shoud understand what is HIV AIDSHIV AIDS is .pdf
First of all we shoud understand what is HIV  AIDSHIV  AIDS is .pdfFirst of all we shoud understand what is HIV  AIDSHIV  AIDS is .pdf
First of all we shoud understand what is HIV AIDSHIV AIDS is .pdf
 

Recently uploaded

Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
ssuserdda66b
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 

Recently uploaded (20)

ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 

#includeiostream struct node {    char value;    struct no.pdf

  • 1. #include struct node { char value; struct node *next; }; class StringOfNode { struct node * head; public: StringOfNode() { head=NULL; } int size() { struct node *p=head; int count=1; while(p) { count++; p=p->next; } return count; } struct node * begin() { return head; } char &operator[](int index) { int i=0; struct node *p=head; while(index!=i) {
  • 2. p=p->next; i++; } return p->value; } void insertFront(char valuee) { struct node * temp=(struct node *)malloc(sizeof(struct node)); temp->value=valuee; temp->next=NULL; if(head==NULL) head=temp; else { temp->next=head; head=temp; } } void insert(char valuee, int pos) { struct node *p=head; struct node * temp=(struct node *)malloc(sizeof(struct node)); temp->value=valuee; temp->next=NULL; int i=0; if(p==NULL) { head=temp; } else { while(i!=pos-1) { p=p->next; i++; }
  • 3. temp->next=p->next; p->next=temp; } } void insertBack(char valuee) { struct node *p=head; struct node * temp=(struct node *)malloc(sizeof(struct node)); temp->value=valuee; temp->next=NULL; if(p==NULL) { head=temp; } else { while(p->next!=NULL) p=p->next; p->next=temp; } } void print() { struct node *p=head; while(p) { std::cout<value<<" "; p=p->next; } } StringOfNode operator+(const StringOfNode& b) { StringOfNode *S;
  • 4. struct node *p=head; while(p->next!=NULL) p=p->next; p->next=S->begin(); } }; int main() { StringOfNode *p1=new StringOfNode; p1->insertBack('b'); p1->insertBack('c'); p1->insertBack('e'); p1->insert('d',2); p1->insertFront('a'); p1->print(); system("pause"); return 0; } Solution #include struct node { char value; struct node *next; }; class StringOfNode { struct node * head; public: StringOfNode() { head=NULL; } int size()
  • 5. { struct node *p=head; int count=1; while(p) { count++; p=p->next; } return count; } struct node * begin() { return head; } char &operator[](int index) { int i=0; struct node *p=head; while(index!=i) { p=p->next; i++; } return p->value; } void insertFront(char valuee) { struct node * temp=(struct node *)malloc(sizeof(struct node)); temp->value=valuee; temp->next=NULL; if(head==NULL) head=temp; else { temp->next=head; head=temp;
  • 6. } } void insert(char valuee, int pos) { struct node *p=head; struct node * temp=(struct node *)malloc(sizeof(struct node)); temp->value=valuee; temp->next=NULL; int i=0; if(p==NULL) { head=temp; } else { while(i!=pos-1) { p=p->next; i++; } temp->next=p->next; p->next=temp; } } void insertBack(char valuee) { struct node *p=head; struct node * temp=(struct node *)malloc(sizeof(struct node)); temp->value=valuee; temp->next=NULL; if(p==NULL) { head=temp; } else
  • 7. { while(p->next!=NULL) p=p->next; p->next=temp; } } void print() { struct node *p=head; while(p) { std::cout<value<<" "; p=p->next; } } StringOfNode operator+(const StringOfNode& b) { StringOfNode *S; struct node *p=head; while(p->next!=NULL) p=p->next; p->next=S->begin(); } }; int main() { StringOfNode *p1=new StringOfNode; p1->insertBack('b'); p1->insertBack('c'); p1->insertBack('e'); p1->insert('d',2); p1->insertFront('a'); p1->print(); system("pause");