SlideShare a Scribd company logo
1 of 15
Download to read offline
Data Structures
PLEASE USING THIS C++ PROGRAM BELOW, I NEED HELP ON IMPLEMENTING
BOTH QUEUE AND STACK TO PRINT "I able"
REVERSE/BACKWARDS(PALINDROME)
#include
#include
using namespace std;
struct st
{
int year;
st *next;
};
class queue
{
public:
int sz,i = 0;
char chr[100];
queue()
{
//constructor for initializing front and rear to NULL
front = NULL;
rear = NULL;
cout << "enter size of queue: ";
cin >> sz;
}
// ~queue()
// {
//
// }
// in the enterqueue, create a new node, assign value and add it to queue
// if F = R = NULL the ( ) else ( )
void enterqueue(int yr, char el)
{
//inserting into queue if queue not overflow
if(i >= sz)
{
cout << "queue over flow";
return;
}
if (front == NULL )
{
front = new st;
front->next = NULL;
front->year = yr;
rear = front;
chr[i] = el;
i++;
}
else
{
st *temp = new st;
temp->year = yr;
rear->next = temp;
rear = temp;
chr[i] = el;
i++;
}
}
char deletequeue()
{
//delete front data from queue if data in the queue
char tr;
int j = 0;
st *temp;
temp = front;
if( front == NULL)
{
cout << "queue under flow";
return 'a';
}
if(front == rear)
{
front = rear = NULL;
return 'a';
}
front = front->next;
delete temp;
tr = chr[0];
i--;
for(j = 0; j < i; j++)
{
chr[j] = chr[j+1];
}
chr[j] = '0';
return tr;
}
bool isempty()
{
//it shows whether queue is empty
if( front == NULL)
{
return true;
}
else
return false;
}
bool isfull()
{
//it shows whether queue is full
if(i == sz)
return true;
else
return false;
}
void display()
{
//it displays queue data with characters of queue if invalid choice is entered
st *tmp;
int j = 0;
cout << " queue is: character tyear";
for(tmp = front; tmp != rear; tmp = tmp->next, j++)
{
cout << " " << chr[j] << " " << tmp->year;
}
cout << " "<year;
}
private:
st *front, *rear;
};
int main()
{
//main method to call queue functions by choice
queue s1;
int ch,yr;
char el;
bool s;
while(1)
{
cout << " 1.ENTERQUEUE 2.DELETEQUEUE 3.ISEMPTY 4.ISFULL 5.EXIT enter
your choice: ";
cin >> ch;
switch(ch)
{
case 1:
if(!s1.isfull())
{
cout << " enter a year : ";
cin >> yr;
cout << " enter a character : ";
cin >> el;
s1.enterqueue(yr, el);
}
else
cout << "insertion not possible";
break;
case 2:
s = s1.isempty();
if(!s)
{
el = s1.deletequeue();
cout << " The character of queue " << el <<" is deleted" << endl;
}
else
cout << " queue is empty.deletion not possible"<< endl;
break;
case 3:
s = s1.isempty();
if(s)
cout << " queue is empty" << endl;
else
cout << " queue is not empty" << endl;
break;
case 4:
s=s1.isfull();
if(s)
cout << " queue is full" << endl;
else
cout << " queue is not full" << endl;
break;
case 5:
exit(0);
default : cout << "invalid choice" << endl;
if(!s1.isempty())
s1.display();
}
}
return (0);
}
Solution
#include
#include
using namespace std;
struct st
{
int year;
st *next;
};
class queue
{
public:
//int sz,i=0;//modified //code modified here// everything is fine with the code except this...
queue is implemented correctly
//you can use this code for ur program;
int sz,i;
char chr[100];
queue()
{
//constructor for initializing front and rear to NULL
front = NULL;
rear = NULL;
cout << "enter size of queue: ";
cin >> sz;
}
// ~queue()
// {
//
// }
// in the enterqueue, create a new node, assign value and add it to queue
// if F = R = NULL the ( ) else ( )
void enterqueue(int yr, char el)
{
//inserting into queue if queue not overflow
if(i >= sz)
{
cout << "queue over flow";
return;
}
if (front == NULL )
{
front = new st;
front->next = NULL;
front->year = yr;
rear = front;
chr[i] = el;
i++;
}
else
{
st *temp = new st;
temp->year = yr;
rear->next = temp;
rear = temp;
chr[i] = el;
i++;
}
}
char deletequeue()
{
//delete front data from queue if data in the queue
char tr;
int j = 0;
st *temp;
temp = front;
if( front == NULL)
{
cout << "queue under flow";
return 'a';
}
if(front == rear)
{
front = rear = NULL;
return 'a';
}
front = front->next;
delete temp;
tr = chr[0];
i--;
for(j = 0; j < i; j++)
{
chr[j] = chr[j+1];
}
chr[j] = '0';
return tr;
}
bool isempty()
{
//it shows whether queue is empty
if( front == NULL)
{
return true;
}
else
return false;
}
bool isfull()
{
//it shows whether queue is full
if(i == sz)
return true;
else
return false;
}
void display()
{
//it displays queue data with characters of queue if invalid choice is entered
st *tmp;
int j = 0;
cout << " queue is: character year";
for(tmp = front; tmp != rear; tmp = tmp->next, j++)
{
cout << " " << chr[j] << "t " << tmp->year;
}
cout << " "<year;
}
private:
st *front, *rear;
};
int main()
{
//main method to call queue functions by choice
queue s1;
int ch,yr;
char el;
bool s;
while(1)
{
cout << " 1.ENTERQUEUE 2.DELETEQUEUE 3.ISEMPTY 4.ISFULL 5.Display
queue 6.EXIT enter your choice: ";
cin >> ch;
switch(ch)
{
case 1:
if(!s1.isfull())
{
cout << " enter a year : ";
cin >> yr;
cout << " enter a character : ";
cin >> el;
s1.enterqueue(yr, el);
}
else
cout << "insertion not possible";
break;
case 2:
s = s1.isempty();
if(!s)
{
el = s1.deletequeue();
cout << " The character of queue " << el <<" is deleted" << endl;
}
else
cout << " queue is empty.deletion not possible"<< endl;
break;
case 3:
s = s1.isempty();
if(s)
cout << " queue is empty" << endl;
else
cout << " queue is not empty" << endl;
break;
case 4:
s=s1.isfull();
if(s)
cout << " queue is full" << endl;
else
cout << " queue is not full" << endl;
break;
case 5:
if(!s1.isempty())
s1.display();
break;
case 6: exit(0);
default : cout << "invalid choice" << endl;
}
}
return (0);
}
output:-
enter size of queue: 3
1.ENTERQUEUE
2.DELETEQUEUE
3.ISEMPTY
4.ISFULL
5.Display queue
6.EXIT
enter your choice: 1
enter a year : 1994
enter a character : a
1.ENTERQUEUE
2.DELETEQUEUE
3.ISEMPTY
4.ISFULL
5.Display queue
6.EXIT
enter your choice: 1
enter a year : 1995
enter a character : b
1.ENTERQUEUE
2.DELETEQUEUE
3.ISEMPTY
4.ISFULL
5.Display queue
6.EXIT
enter your choice: 1
enter a year : 1996
enter a character : c
1.ENTERQUEUE
2.DELETEQUEUE
3.ISEMPTY
4.ISFULL
5.Display queue
6.EXIT
enter your choice: 1
insertion not possible
1.ENTERQUEUE
2.DELETEQUEUE
3.ISEMPTY
4.ISFULL
5.Display queue
6.EXIT
enter your choice: 3
queue is not empty
1.ENTERQUEUE
2.DELETEQUEUE
3.ISEMPTY
4.ISFULL
5.Display queue
6.EXIT
enter your choice: 4
queue is full
1.ENTERQUEUE
2.DELETEQUEUE
3.ISEMPTY
4.ISFULL
5.Display queue
6.EXIT
enter your choice: 5
queue is:
character year
a 1994
b 1995
c 1996
1.ENTERQUEUE
2.DELETEQUEUE
3.ISEMPTY
4.ISFULL
5.Display queue
6.EXIT
enter your choice: 2
The character of queue a is deleted
1.ENTERQUEUE
2.DELETEQUEUE
3.ISEMPTY
4.ISFULL
5.Display queue
6.EXIT
enter your choice: 5
queue is:
character year
b 1995
c 1996
1.ENTERQUEUE
2.DELETEQUEUE
3.ISEMPTY
4.ISFULL
5.Display queue
6.EXIT
enter your choice:6

More Related Content

Similar to Data StructuresPLEASE USING THIS C++ PROGRAM BELOW, I NEED HEL.pdf

#include iostream#include d_node.h #include d_nodel.h.docx
#include iostream#include d_node.h #include d_nodel.h.docx#include iostream#include d_node.h #include d_nodel.h.docx
#include iostream#include d_node.h #include d_nodel.h.docxajoy21
 
Datastructures asignment
Datastructures asignmentDatastructures asignment
Datastructures asignmentsreekanth3dce
 
#include String.hpp#include ..Functionsfunctions.hpp.docx
#include String.hpp#include ..Functionsfunctions.hpp.docx#include String.hpp#include ..Functionsfunctions.hpp.docx
#include String.hpp#include ..Functionsfunctions.hpp.docxgertrudebellgrove
 
calc3build# calc3bison -y -d calc3.yflex calc3.lgcc -c .docx
calc3build# calc3bison -y -d calc3.yflex calc3.lgcc -c .docxcalc3build# calc3bison -y -d calc3.yflex calc3.lgcc -c .docx
calc3build# calc3bison -y -d calc3.yflex calc3.lgcc -c .docxRAHUL126667
 
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.pdfforladies
 
1- The design of a singly-linked list below is a picture of the functi (1).pdf
1- The design of a singly-linked list below is a picture of the functi (1).pdf1- The design of a singly-linked list below is a picture of the functi (1).pdf
1- The design of a singly-linked list below is a picture of the functi (1).pdfafgt2012
 
Program In C You are required to write an interactive C program that.pdf
Program In C You are required to write an interactive C program that.pdfProgram In C You are required to write an interactive C program that.pdf
Program In C You are required to write an interactive C program that.pdfamitbagga0808
 
C++ projectMachine Problem 7 - HashingWrite a program to do the .pdf
C++ projectMachine Problem 7 - HashingWrite a program to do the .pdfC++ projectMachine Problem 7 - HashingWrite a program to do the .pdf
C++ projectMachine Problem 7 - HashingWrite a program to do the .pdffeelinggift
 
Microsoft Word Hw#1
Microsoft Word   Hw#1Microsoft Word   Hw#1
Microsoft Word Hw#1kkkseld
 
#include iostream #include fstream #include stack #inclu.pdf
#include iostream #include fstream #include stack #inclu.pdf#include iostream #include fstream #include stack #inclu.pdf
#include iostream #include fstream #include stack #inclu.pdfnageswara1958
 
VTU DSA Lab Manual
VTU DSA Lab ManualVTU DSA Lab Manual
VTU DSA Lab ManualAkhilaaReddy
 
6 c control statements branching &amp; jumping
6 c control statements branching &amp; jumping6 c control statements branching &amp; jumping
6 c control statements branching &amp; jumpingMomenMostafa
 
Hangman Game Programming in C (coding)
Hangman Game Programming in C (coding)Hangman Game Programming in C (coding)
Hangman Game Programming in C (coding)hasan0812
 
Were writing code for a project that dynamically allocates an arra.pdf
Were writing code for a project that dynamically allocates an arra.pdfWere writing code for a project that dynamically allocates an arra.pdf
Were writing code for a project that dynamically allocates an arra.pdffsenterprises
 
Help with this substitution program- line 3 of the output is different.pdf
Help with this substitution program- line 3 of the output is different.pdfHelp with this substitution program- line 3 of the output is different.pdf
Help with this substitution program- line 3 of the output is different.pdfgaurav444u
 
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYDATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYMalikireddy Bramhananda Reddy
 

Similar to Data StructuresPLEASE USING THIS C++ PROGRAM BELOW, I NEED HEL.pdf (20)

#include iostream#include d_node.h #include d_nodel.h.docx
#include iostream#include d_node.h #include d_nodel.h.docx#include iostream#include d_node.h #include d_nodel.h.docx
#include iostream#include d_node.h #include d_nodel.h.docx
 
Datastructures asignment
Datastructures asignmentDatastructures asignment
Datastructures asignment
 
#include String.hpp#include ..Functionsfunctions.hpp.docx
#include String.hpp#include ..Functionsfunctions.hpp.docx#include String.hpp#include ..Functionsfunctions.hpp.docx
#include String.hpp#include ..Functionsfunctions.hpp.docx
 
calc3build# calc3bison -y -d calc3.yflex calc3.lgcc -c .docx
calc3build# calc3bison -y -d calc3.yflex calc3.lgcc -c .docxcalc3build# calc3bison -y -d calc3.yflex calc3.lgcc -c .docx
calc3build# calc3bison -y -d calc3.yflex calc3.lgcc -c .docx
 
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
 
1- The design of a singly-linked list below is a picture of the functi (1).pdf
1- The design of a singly-linked list below is a picture of the functi (1).pdf1- The design of a singly-linked list below is a picture of the functi (1).pdf
1- The design of a singly-linked list below is a picture of the functi (1).pdf
 
Program In C You are required to write an interactive C program that.pdf
Program In C You are required to write an interactive C program that.pdfProgram In C You are required to write an interactive C program that.pdf
Program In C You are required to write an interactive C program that.pdf
 
C++ projectMachine Problem 7 - HashingWrite a program to do the .pdf
C++ projectMachine Problem 7 - HashingWrite a program to do the .pdfC++ projectMachine Problem 7 - HashingWrite a program to do the .pdf
C++ projectMachine Problem 7 - HashingWrite a program to do the .pdf
 
Microsoft Word Hw#1
Microsoft Word   Hw#1Microsoft Word   Hw#1
Microsoft Word Hw#1
 
#include iostream #include fstream #include stack #inclu.pdf
#include iostream #include fstream #include stack #inclu.pdf#include iostream #include fstream #include stack #inclu.pdf
#include iostream #include fstream #include stack #inclu.pdf
 
VTU DSA Lab Manual
VTU DSA Lab ManualVTU DSA Lab Manual
VTU DSA Lab Manual
 
Qprgs
QprgsQprgs
Qprgs
 
6 c control statements branching &amp; jumping
6 c control statements branching &amp; jumping6 c control statements branching &amp; jumping
6 c control statements branching &amp; jumping
 
Hangman Game Programming in C (coding)
Hangman Game Programming in C (coding)Hangman Game Programming in C (coding)
Hangman Game Programming in C (coding)
 
Were writing code for a project that dynamically allocates an arra.pdf
Were writing code for a project that dynamically allocates an arra.pdfWere writing code for a project that dynamically allocates an arra.pdf
Were writing code for a project that dynamically allocates an arra.pdf
 
Help with this substitution program- line 3 of the output is different.pdf
Help with this substitution program- line 3 of the output is different.pdfHelp with this substitution program- line 3 of the output is different.pdf
Help with this substitution program- line 3 of the output is different.pdf
 
c programming
c programmingc programming
c programming
 
DataTypes.ppt
DataTypes.pptDataTypes.ppt
DataTypes.ppt
 
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYDATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
 
week-18x
week-18xweek-18x
week-18x
 

More from rozakashif85

Give background information concerning EMT and include what is known.pdf
Give background information concerning EMT and include what is known.pdfGive background information concerning EMT and include what is known.pdf
Give background information concerning EMT and include what is known.pdfrozakashif85
 
Explain how the current economic recession differs from the depressio.pdf
Explain how the current economic recession differs from the depressio.pdfExplain how the current economic recession differs from the depressio.pdf
Explain how the current economic recession differs from the depressio.pdfrozakashif85
 
Does yeast uses CopI and CopII formation for vesicle budding to grow.pdf
Does yeast uses CopI and CopII formation for vesicle budding to grow.pdfDoes yeast uses CopI and CopII formation for vesicle budding to grow.pdf
Does yeast uses CopI and CopII formation for vesicle budding to grow.pdfrozakashif85
 
DNA molecules consist of chemically linked sequences of the bases ad.pdf
DNA molecules consist of chemically linked sequences of the bases ad.pdfDNA molecules consist of chemically linked sequences of the bases ad.pdf
DNA molecules consist of chemically linked sequences of the bases ad.pdfrozakashif85
 
Count Red Nodes. Write a program that computes the percentage of red.pdf
Count Red Nodes. Write a program that computes the percentage of red.pdfCount Red Nodes. Write a program that computes the percentage of red.pdf
Count Red Nodes. Write a program that computes the percentage of red.pdfrozakashif85
 
apple 2008 historically what were Apples major competitive advanta.pdf
apple 2008 historically what were Apples major competitive advanta.pdfapple 2008 historically what were Apples major competitive advanta.pdf
apple 2008 historically what were Apples major competitive advanta.pdfrozakashif85
 
A partial results from a PERT analysis for a project with 50 activit.pdf
A partial results from a PERT analysis for a project with 50 activit.pdfA partial results from a PERT analysis for a project with 50 activit.pdf
A partial results from a PERT analysis for a project with 50 activit.pdfrozakashif85
 
briefly write about the variability of natural systems and the signi.pdf
briefly write about the variability of natural systems and the signi.pdfbriefly write about the variability of natural systems and the signi.pdf
briefly write about the variability of natural systems and the signi.pdfrozakashif85
 
A graph is symmetric with respect to the vertical line corresponding.pdf
A graph is symmetric with respect to the vertical line corresponding.pdfA graph is symmetric with respect to the vertical line corresponding.pdf
A graph is symmetric with respect to the vertical line corresponding.pdfrozakashif85
 
X-Linked Recessive Write three rules to keep in mind when counseling .pdf
X-Linked Recessive Write three rules to keep in mind when counseling .pdfX-Linked Recessive Write three rules to keep in mind when counseling .pdf
X-Linked Recessive Write three rules to keep in mind when counseling .pdfrozakashif85
 
Write a Java Class to Implement a Generic Linked ListYour list mus.pdf
Write a Java Class to Implement a Generic Linked ListYour list mus.pdfWrite a Java Class to Implement a Generic Linked ListYour list mus.pdf
Write a Java Class to Implement a Generic Linked ListYour list mus.pdfrozakashif85
 
Write a class (BasketballTeam) encapsulating the concept of a tea.pdf
Write a class (BasketballTeam) encapsulating the concept of a tea.pdfWrite a class (BasketballTeam) encapsulating the concept of a tea.pdf
Write a class (BasketballTeam) encapsulating the concept of a tea.pdfrozakashif85
 
Which of the following would you expect to happen in a plant that doe.pdf
Which of the following would you expect to happen in a plant that doe.pdfWhich of the following would you expect to happen in a plant that doe.pdf
Which of the following would you expect to happen in a plant that doe.pdfrozakashif85
 
What is the value of including personal information about yourself a.pdf
What is the value of including personal information about yourself a.pdfWhat is the value of including personal information about yourself a.pdf
What is the value of including personal information about yourself a.pdfrozakashif85
 
What is a voluntary response sampleSolutionVoluntary response.pdf
What is a voluntary response sampleSolutionVoluntary response.pdfWhat is a voluntary response sampleSolutionVoluntary response.pdf
What is a voluntary response sampleSolutionVoluntary response.pdfrozakashif85
 
What adaptive benefit do these abilities give wolbachia In oth.pdf
What adaptive benefit do these abilities give wolbachia In oth.pdfWhat adaptive benefit do these abilities give wolbachia In oth.pdf
What adaptive benefit do these abilities give wolbachia In oth.pdfrozakashif85
 
Think about autumn (Fall season) in places like New England (Pennsyl.pdf
Think about autumn (Fall season) in places like New England (Pennsyl.pdfThink about autumn (Fall season) in places like New England (Pennsyl.pdf
Think about autumn (Fall season) in places like New England (Pennsyl.pdfrozakashif85
 
The orange is which type of fruit Simple - Legume Simple - Drupe .pdf
The orange is which type of fruit  Simple - Legume  Simple - Drupe  .pdfThe orange is which type of fruit  Simple - Legume  Simple - Drupe  .pdf
The orange is which type of fruit Simple - Legume Simple - Drupe .pdfrozakashif85
 
The _________ is the protective chamber that houses the ovule and Lat.pdf
The _________ is the protective chamber that houses the ovule and Lat.pdfThe _________ is the protective chamber that houses the ovule and Lat.pdf
The _________ is the protective chamber that houses the ovule and Lat.pdfrozakashif85
 
Suppose X follows a normal distribution with mean=1 and variance=4. .pdf
Suppose X follows a normal distribution with mean=1 and variance=4. .pdfSuppose X follows a normal distribution with mean=1 and variance=4. .pdf
Suppose X follows a normal distribution with mean=1 and variance=4. .pdfrozakashif85
 

More from rozakashif85 (20)

Give background information concerning EMT and include what is known.pdf
Give background information concerning EMT and include what is known.pdfGive background information concerning EMT and include what is known.pdf
Give background information concerning EMT and include what is known.pdf
 
Explain how the current economic recession differs from the depressio.pdf
Explain how the current economic recession differs from the depressio.pdfExplain how the current economic recession differs from the depressio.pdf
Explain how the current economic recession differs from the depressio.pdf
 
Does yeast uses CopI and CopII formation for vesicle budding to grow.pdf
Does yeast uses CopI and CopII formation for vesicle budding to grow.pdfDoes yeast uses CopI and CopII formation for vesicle budding to grow.pdf
Does yeast uses CopI and CopII formation for vesicle budding to grow.pdf
 
DNA molecules consist of chemically linked sequences of the bases ad.pdf
DNA molecules consist of chemically linked sequences of the bases ad.pdfDNA molecules consist of chemically linked sequences of the bases ad.pdf
DNA molecules consist of chemically linked sequences of the bases ad.pdf
 
Count Red Nodes. Write a program that computes the percentage of red.pdf
Count Red Nodes. Write a program that computes the percentage of red.pdfCount Red Nodes. Write a program that computes the percentage of red.pdf
Count Red Nodes. Write a program that computes the percentage of red.pdf
 
apple 2008 historically what were Apples major competitive advanta.pdf
apple 2008 historically what were Apples major competitive advanta.pdfapple 2008 historically what were Apples major competitive advanta.pdf
apple 2008 historically what were Apples major competitive advanta.pdf
 
A partial results from a PERT analysis for a project with 50 activit.pdf
A partial results from a PERT analysis for a project with 50 activit.pdfA partial results from a PERT analysis for a project with 50 activit.pdf
A partial results from a PERT analysis for a project with 50 activit.pdf
 
briefly write about the variability of natural systems and the signi.pdf
briefly write about the variability of natural systems and the signi.pdfbriefly write about the variability of natural systems and the signi.pdf
briefly write about the variability of natural systems and the signi.pdf
 
A graph is symmetric with respect to the vertical line corresponding.pdf
A graph is symmetric with respect to the vertical line corresponding.pdfA graph is symmetric with respect to the vertical line corresponding.pdf
A graph is symmetric with respect to the vertical line corresponding.pdf
 
X-Linked Recessive Write three rules to keep in mind when counseling .pdf
X-Linked Recessive Write three rules to keep in mind when counseling .pdfX-Linked Recessive Write three rules to keep in mind when counseling .pdf
X-Linked Recessive Write three rules to keep in mind when counseling .pdf
 
Write a Java Class to Implement a Generic Linked ListYour list mus.pdf
Write a Java Class to Implement a Generic Linked ListYour list mus.pdfWrite a Java Class to Implement a Generic Linked ListYour list mus.pdf
Write a Java Class to Implement a Generic Linked ListYour list mus.pdf
 
Write a class (BasketballTeam) encapsulating the concept of a tea.pdf
Write a class (BasketballTeam) encapsulating the concept of a tea.pdfWrite a class (BasketballTeam) encapsulating the concept of a tea.pdf
Write a class (BasketballTeam) encapsulating the concept of a tea.pdf
 
Which of the following would you expect to happen in a plant that doe.pdf
Which of the following would you expect to happen in a plant that doe.pdfWhich of the following would you expect to happen in a plant that doe.pdf
Which of the following would you expect to happen in a plant that doe.pdf
 
What is the value of including personal information about yourself a.pdf
What is the value of including personal information about yourself a.pdfWhat is the value of including personal information about yourself a.pdf
What is the value of including personal information about yourself a.pdf
 
What is a voluntary response sampleSolutionVoluntary response.pdf
What is a voluntary response sampleSolutionVoluntary response.pdfWhat is a voluntary response sampleSolutionVoluntary response.pdf
What is a voluntary response sampleSolutionVoluntary response.pdf
 
What adaptive benefit do these abilities give wolbachia In oth.pdf
What adaptive benefit do these abilities give wolbachia In oth.pdfWhat adaptive benefit do these abilities give wolbachia In oth.pdf
What adaptive benefit do these abilities give wolbachia In oth.pdf
 
Think about autumn (Fall season) in places like New England (Pennsyl.pdf
Think about autumn (Fall season) in places like New England (Pennsyl.pdfThink about autumn (Fall season) in places like New England (Pennsyl.pdf
Think about autumn (Fall season) in places like New England (Pennsyl.pdf
 
The orange is which type of fruit Simple - Legume Simple - Drupe .pdf
The orange is which type of fruit  Simple - Legume  Simple - Drupe  .pdfThe orange is which type of fruit  Simple - Legume  Simple - Drupe  .pdf
The orange is which type of fruit Simple - Legume Simple - Drupe .pdf
 
The _________ is the protective chamber that houses the ovule and Lat.pdf
The _________ is the protective chamber that houses the ovule and Lat.pdfThe _________ is the protective chamber that houses the ovule and Lat.pdf
The _________ is the protective chamber that houses the ovule and Lat.pdf
 
Suppose X follows a normal distribution with mean=1 and variance=4. .pdf
Suppose X follows a normal distribution with mean=1 and variance=4. .pdfSuppose X follows a normal distribution with mean=1 and variance=4. .pdf
Suppose X follows a normal distribution with mean=1 and variance=4. .pdf
 

Recently uploaded

18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
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.pdfQucHHunhnh
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 

Recently uploaded (20)

18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
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
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 

Data StructuresPLEASE USING THIS C++ PROGRAM BELOW, I NEED HEL.pdf

  • 1. Data Structures PLEASE USING THIS C++ PROGRAM BELOW, I NEED HELP ON IMPLEMENTING BOTH QUEUE AND STACK TO PRINT "I able" REVERSE/BACKWARDS(PALINDROME) #include #include using namespace std; struct st { int year; st *next; }; class queue { public: int sz,i = 0; char chr[100]; queue() { //constructor for initializing front and rear to NULL front = NULL; rear = NULL; cout << "enter size of queue: "; cin >> sz; } // ~queue()
  • 2. // { // // } // in the enterqueue, create a new node, assign value and add it to queue // if F = R = NULL the ( ) else ( ) void enterqueue(int yr, char el) { //inserting into queue if queue not overflow if(i >= sz) { cout << "queue over flow"; return; } if (front == NULL ) { front = new st; front->next = NULL; front->year = yr; rear = front; chr[i] = el; i++; } else { st *temp = new st; temp->year = yr; rear->next = temp; rear = temp; chr[i] = el;
  • 3. i++; } } char deletequeue() { //delete front data from queue if data in the queue char tr; int j = 0; st *temp; temp = front; if( front == NULL) { cout << "queue under flow"; return 'a'; } if(front == rear) { front = rear = NULL; return 'a'; } front = front->next; delete temp; tr = chr[0]; i--; for(j = 0; j < i; j++) { chr[j] = chr[j+1]; } chr[j] = '0';
  • 4. return tr; } bool isempty() { //it shows whether queue is empty if( front == NULL) { return true; } else return false; } bool isfull() { //it shows whether queue is full if(i == sz) return true; else return false; } void display() { //it displays queue data with characters of queue if invalid choice is entered st *tmp; int j = 0; cout << " queue is: character tyear"; for(tmp = front; tmp != rear; tmp = tmp->next, j++)
  • 5. { cout << " " << chr[j] << " " << tmp->year; } cout << " "<year; } private: st *front, *rear; }; int main() { //main method to call queue functions by choice queue s1; int ch,yr; char el; bool s; while(1) { cout << " 1.ENTERQUEUE 2.DELETEQUEUE 3.ISEMPTY 4.ISFULL 5.EXIT enter your choice: "; cin >> ch; switch(ch) { case 1: if(!s1.isfull()) { cout << " enter a year : "; cin >> yr; cout << " enter a character : "; cin >> el; s1.enterqueue(yr, el);
  • 6. } else cout << "insertion not possible"; break; case 2: s = s1.isempty(); if(!s) { el = s1.deletequeue(); cout << " The character of queue " << el <<" is deleted" << endl; } else cout << " queue is empty.deletion not possible"<< endl; break; case 3: s = s1.isempty(); if(s) cout << " queue is empty" << endl; else cout << " queue is not empty" << endl; break; case 4: s=s1.isfull(); if(s) cout << " queue is full" << endl; else cout << " queue is not full" << endl; break;
  • 7. case 5: exit(0); default : cout << "invalid choice" << endl; if(!s1.isempty()) s1.display(); } } return (0); } Solution #include #include using namespace std; struct st { int year; st *next; }; class queue { public: //int sz,i=0;//modified //code modified here// everything is fine with the code except this... queue is implemented correctly //you can use this code for ur program; int sz,i; char chr[100]; queue() { //constructor for initializing front and rear to NULL front = NULL; rear = NULL;
  • 8. cout << "enter size of queue: "; cin >> sz; } // ~queue() // { // // } // in the enterqueue, create a new node, assign value and add it to queue // if F = R = NULL the ( ) else ( ) void enterqueue(int yr, char el) { //inserting into queue if queue not overflow if(i >= sz) { cout << "queue over flow"; return; } if (front == NULL ) { front = new st; front->next = NULL; front->year = yr; rear = front; chr[i] = el; i++; } else { st *temp = new st; temp->year = yr;
  • 9. rear->next = temp; rear = temp; chr[i] = el; i++; } } char deletequeue() { //delete front data from queue if data in the queue char tr; int j = 0; st *temp; temp = front; if( front == NULL) { cout << "queue under flow"; return 'a'; } if(front == rear) { front = rear = NULL; return 'a'; } front = front->next; delete temp; tr = chr[0]; i--; for(j = 0; j < i; j++) { chr[j] = chr[j+1]; }
  • 10. chr[j] = '0'; return tr; } bool isempty() { //it shows whether queue is empty if( front == NULL) { return true; } else return false; } bool isfull() { //it shows whether queue is full if(i == sz) return true; else return false; } void display() { //it displays queue data with characters of queue if invalid choice is entered st *tmp; int j = 0; cout << " queue is: character year"; for(tmp = front; tmp != rear; tmp = tmp->next, j++) {
  • 11. cout << " " << chr[j] << "t " << tmp->year; } cout << " "<year; } private: st *front, *rear; }; int main() { //main method to call queue functions by choice queue s1; int ch,yr; char el; bool s; while(1) { cout << " 1.ENTERQUEUE 2.DELETEQUEUE 3.ISEMPTY 4.ISFULL 5.Display queue 6.EXIT enter your choice: "; cin >> ch; switch(ch) { case 1: if(!s1.isfull()) { cout << " enter a year : "; cin >> yr; cout << " enter a character : "; cin >> el; s1.enterqueue(yr, el); } else cout << "insertion not possible"; break;
  • 12. case 2: s = s1.isempty(); if(!s) { el = s1.deletequeue(); cout << " The character of queue " << el <<" is deleted" << endl; } else cout << " queue is empty.deletion not possible"<< endl; break; case 3: s = s1.isempty(); if(s) cout << " queue is empty" << endl; else cout << " queue is not empty" << endl; break; case 4: s=s1.isfull(); if(s) cout << " queue is full" << endl; else cout << " queue is not full" << endl; break; case 5: if(!s1.isempty()) s1.display(); break;
  • 13. case 6: exit(0); default : cout << "invalid choice" << endl; } } return (0); } output:- enter size of queue: 3 1.ENTERQUEUE 2.DELETEQUEUE 3.ISEMPTY 4.ISFULL 5.Display queue 6.EXIT enter your choice: 1 enter a year : 1994 enter a character : a 1.ENTERQUEUE 2.DELETEQUEUE 3.ISEMPTY 4.ISFULL 5.Display queue 6.EXIT enter your choice: 1 enter a year : 1995 enter a character : b 1.ENTERQUEUE 2.DELETEQUEUE 3.ISEMPTY 4.ISFULL 5.Display queue 6.EXIT enter your choice: 1 enter a year : 1996
  • 14. enter a character : c 1.ENTERQUEUE 2.DELETEQUEUE 3.ISEMPTY 4.ISFULL 5.Display queue 6.EXIT enter your choice: 1 insertion not possible 1.ENTERQUEUE 2.DELETEQUEUE 3.ISEMPTY 4.ISFULL 5.Display queue 6.EXIT enter your choice: 3 queue is not empty 1.ENTERQUEUE 2.DELETEQUEUE 3.ISEMPTY 4.ISFULL 5.Display queue 6.EXIT enter your choice: 4 queue is full 1.ENTERQUEUE 2.DELETEQUEUE 3.ISEMPTY 4.ISFULL 5.Display queue 6.EXIT enter your choice: 5 queue is: character year a 1994 b 1995
  • 15. c 1996 1.ENTERQUEUE 2.DELETEQUEUE 3.ISEMPTY 4.ISFULL 5.Display queue 6.EXIT enter your choice: 2 The character of queue a is deleted 1.ENTERQUEUE 2.DELETEQUEUE 3.ISEMPTY 4.ISFULL 5.Display queue 6.EXIT enter your choice: 5 queue is: character year b 1995 c 1996 1.ENTERQUEUE 2.DELETEQUEUE 3.ISEMPTY 4.ISFULL 5.Display queue 6.EXIT enter your choice:6