Question

Programming Language:C++      Could someone give me a quick example of implementing a stack<string> into a...

Programming Language:C++

     Could someone give me a quick example of implementing a stack<string> into a double link list with an explanation. Also if possible how to be able to add, remove, or modify the strings of the stack inside the link list thank you

Homework Answers

Answer #1

Implemetation of Stack using double link list.

Please hit that like button or thumbs-up button to motivate me.(It really helps, just take 1-2 seconds hope you will do that)>3

Thank you!!

I have done this implementation with add, remove, or display.

Stack.cpp

#include<iostream>
#include <stdio.h>
#include<stdlib.h>

using namespace std;
struct node
{
int num;
struct node *left;
struct node *right;
};

struct node* receivenode( )
{
return ( struct node *)malloc( sizeof( struct node ));
};
struct node* top; int c=0;
struct node* add( struct node *);
struct node* del( struct node *);
void display( struct node *);

int main()
{
struct node *A;
int ch;
A = NULL; top=A;
while( 1 )
{
// User menu to show what to do
printf("1.Add elements\n");
printf("2.Delete element\n");
printf("3.Display\n");
printf("4.Exit \n");
printf("Enter your Choice:");
scanf("%d", &ch );
if( ch == 1 )
A = add ( A );
else if( ch == 2 )
A=del(A);
else if(ch==3)
display( A );
else if( ch == 4 )
exit(0);
}
}
// Adding numbers in stack using Double Linked list
struct node* add( struct node *START)
{
struct node *B;
if( START == NULL )
{
START = receivenode();
B =top=START;
B->left=NULL;
}
else
{ B=receivenode();
top->right=B; B->left=top;
top=B;
}
printf("Enter a number to add:\n"); c++;
scanf("%d",&B->num );
B->right= NULL;
return START;
}
// Deleting numbers in stack using Double Linked list
struct node* del( struct node *START)
{
struct node *B;
if(( START== NULL)&&(c<1))
{
printf("Underflow\n");
return START;
}
B=top;
printf("The deleted number is : %d\n",B->num);
if(c!=1)
{top=B->left;
B->left= NULL; top->right=NULL;}
else if(c==1)
{START=NULL;}
c--;
return START;
}
// Display numbers which available in stack
void display( struct node *B)
{ if(B==NULL)
{
printf("Nothing Found!\n");
return;
}
while( B != NULL )
{
printf("%d ",B->num);
B = B->right;
}
printf("\n");
}

Output:-

Please refer to screenshot

Again,Please hit that like button.

Thank you!!

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
I have a list of things for review in C programming, could you please give me...
I have a list of things for review in C programming, could you please give me an example and a brief explanation for each question... Thank you very much 5. Create functions that can return pointers or functions that can return structs 6. Analyze code that uses predefined strings such as  strlen, strcat, strncat, and  strtok 7. Create syntax that can perform file input and output 8. Distinguish between array and pointer notation and use both in syntax
C PROGRAMMING Doubly Linked List For this program you’ll implement a doubly linked list of strings....
C PROGRAMMING Doubly Linked List For this program you’ll implement a doubly linked list of strings. You must base your code on the doubly linked list implementation given in my Week 8 slides. Change the code so that instead of an ‘int’ each node stores a string (choose a suitable size). Each node should also have a next node pointer, and previous node pointer. Then write functions to implement the following linked list operations: • A printList function that prints...
How could I create a very basic assembly program that is able to use string literals,...
How could I create a very basic assembly program that is able to use string literals, reserved words, and identifiers? I also need to process some directives, instructions, and labels as well. Could someone generate a simple assembly program to do these things? Thank you! My apologies, x86 processors. It's also a 32-bit program! We are using Visual Studio, and writing 32-bit programs. This program can literally do anything, as long as it meets the following requirements as described above.
could you please give me an example of Data Collection Activity with Required Activity Component :...
could you please give me an example of Data Collection Activity with Required Activity Component : - Description of the Study - Variable of Interest - Population - Sample - Data Collection Method - Measures are taken to ensure a representative sample was collected - Raw Data, Example: For this study, the data might look as follows: 230, 543, 109, 476, 219, 72, 789, 111, 360, 967, 445, 301, 836, 281, 547, 682, 725, 370, 177, 265, 484, 638, 40,...
Can someone please give me a detailed explanation of how to solve these? thank you! QUESTION...
Can someone please give me a detailed explanation of how to solve these? thank you! QUESTION 4 Use the following information to answer the next two questions. Suppose the spot quotes for the Mexican pesos and pounds are $.1252‑58 and $1.055‑62, respectively. What is the ask quote for pounds in terms of pesos? Round intermediate calculations to four decimal places. 8.4420 8.4265 8.4824 8.3125 Question 5 Find the bid quote for pounds in terms of pesos. Round intermediate steps and...
I've posted this question like 3 times now and I can't seem to find someone that...
I've posted this question like 3 times now and I can't seem to find someone that is able to answer it. Please can someone help me code this? Thank you!! Programming Project #4 – Programmer Jones and the Temple of Gloom Part 1 The stack data structure plays a pivotal role in the design of computer games. Any algorithm that requires the user to retrace their steps is a perfect candidate for using a stack. In this simple game you...
Assignment goals • Build experience solving problems by implementing branch and loop algorithms. • Become able...
Assignment goals • Build experience solving problems by implementing branch and loop algorithms. • Become able to program using control structures. • Understand and implement string comparison in Java. • Develop skills required to write and debug Java programs. Description You program must start and keep dialog with the user. Please create the first prompt for the dialog. After that your program must accept the user’s response and echo it (output to screen) in upper case and adding the question...
Strings The example program below, with a few notes following, shows how strings work in C++....
Strings The example program below, with a few notes following, shows how strings work in C++. Example 1: #include <iostream> using namespace std; int main() { string s="eggplant"; string t="okra"; cout<<s[2]<<endl; cout<< s.length()<<endl; ​//prints 8 cout<<s.substr(1,4)<<endl; ​//prints ggpl...kind of like a slice, but the second num is the length of the piece cout<<s+t<<endl; //concatenates: prints eggplantokra cout<<s+"a"<<endl; cout<<s.append("a")<<endl; ​//prints eggplanta: see Note 1 below //cout<<s.append(t[1])<<endl; ​//an error; see Note 1 cout<<s.append(t.substr(1,1))<<endl; ​//prints eggplantak; see Note 1 cout<<s.find("gg")<<endl; if (s.find("gg")!=-1) cout<<"found...
Can someone hel me with this federal income tax question please. What is the best filing...
Can someone hel me with this federal income tax question please. What is the best filing status in general, for the following scenarios? Provide explanation plese. Mike is a 25 years old person who recently graduate from College in May 2020. In August 2020, Anderson started working for Google and received an annual salary of $55k. James get married in Jan 2020. By August 2020, James found out that his wife is having an affair with her ex-boyfriend. For that...
In this lesson we provided you with a list of common questions asked during an interview:...
In this lesson we provided you with a list of common questions asked during an interview: 1. Tell me about yourself, and the work experiences you have had. 2. Give an example of a time when you had a great success at work. 3. Give an example of a time when you were responsible for a major task at work and you were not successful. 4. How would you describe yourself? 5. What does your ideal job look like? 6....
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT