QuestionQuestion

ASSIGNMENT:

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 PreviewSolution 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.

50% discount

Hours
Minutes
Seconds
$45.00 $22.50
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Data Structures and Algorithms Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats