Question
2) Obtain a String from user input, and output whether this string belongs to the language
L = {AnBn, n>=0}. Language L include all the strings of only As and Bs where: all letter Bs appear after letter As, and the number of letter As is the same as the number of letter Bs. Requirement: use stack operations (of link-based stack) to achieve above function.
3) Create and populate a stack that achieves the following two objectives:
a) The links-based implementation of the stack has the following items in sequence:
top -> 1 -> 2 -> 3 -> 4 -> 5
b) Implement a function that takes an ADTStack as a parameter and creates and returns a second stack that is the reverse of the parameter stack. For example, if the parameter stack’s initial state is what is above in part a), then the new stack is:
top -> 5 -> 4 -> 3 -> 2 ->1
Solution Preview
These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.
import java.util.Scanner;class Node{
char value;
Node next;
public Node(char value){
this.value = value;
next = null;
}
public char getValue(){
return value;
}
public Node getNext() {
return next;
}
public void setNext(Node next) {
this.next = next;
}
}
class StackLinkedList{
private Node head;
public StackLinkedList(){
head = null;
}
public void push(char value){
Node node = new Node(value);
if(head == null){
head = node;
}else {
node.setNext(head);
head = node;
}
}
public char pop(){
if(!isEmpty()){
Node d = head;
head = d.getNext();
return d.getValue();
}else {
return ' ';
}
}...
By purchasing this solution you'll be able to access the following files:
Solution.zip.