AnBnAn.cpp
---------------------------------------------------------
#include "LQ.h"
#include <iostream>
#include <string>
using namespace std;
int main()
{
LLQ queue;
int userOption = -1;
string test = "aaaabbbbaaaa";
int stringLength = test.length();
for (int i = 0; i < stringLength; i++)
//placing the string character into a linked list
{
queue.createList(test[i]);
}
while (userOption != NULL)
{
cout << "1. View
list" << endl;
cout << "2. Insert
to list" << endl;
cout << "3. Remove
from list" << endl;
cout << "4.
Inspect list " << endl;
cout << "0. Exit
Program" << endl << endl;
cout << "Enter a
option: ";
cin >> userOption;
switch
(userOption)
{
case 1:
cout << "\ncase 1 test, view list\n" << endl;
queue.viewList();
break;
case 2:
cout << "\ncase 2 test" << endl;
queue.insert('g');
break;
case 3:
cout << "\ncase 3 test" << endl;
if (!queue.is_empty())
queue.remove();
else
cout << "\nERROR Queue is empty" << endl;
break;
case 4:
cout << "\ncase 3 test" << endl;
if (!queue.is_empty())
{
if (queue.inspectList())
cout << "\nlist is valid\n" << endl;
else
cout << "\nlist is not valid does not follow rules" <<
endl;
}
else
cout << "\nERROR Queue is empty" << endl;
break;
}
cout <<
endl;
}
return 0;
}
-----------------------------------------------------------
LQ.cpp
-----------------------------------
#include "LQ.h"
#include <iostream>
using namespace std;
bool LLQ::is_full() const
{
return false;
}
bool LLQ::is_empty() const
{
return (head==NULL);
}
void LLQ::remove()
{
//removing the first element in the list
node *nodePtr;
nodePtr = head;
head = nodePtr->next;
}
void LLQ::insert(char insertChar)
{
node *newNode;
node *nodePtr;
//placing a value into newNode and assigning
and pointing the next to null
newNode = new node;
newNode->character = insertChar;
newNode->next = NULL;
if (!head)
{ //if list is empty
head = newNode;
nodePtr = head;
newNode->next =
NULL;
}
else
{//if list not empty
nodePtr = head;
while
(nodePtr->next)
nodePtr = nodePtr->next;
nodePtr->next =
newNode;
}
}
void LLQ::createList(char insert)
{
node *newNode;
node *nodePtr;
newNode = new node;
newNode->character = insert;
newNode->next = NULL;
if (!head)
{ //if list is empty
head = newNode;
nodePtr = head;
newNode->next =
NULL;
}
else
{//if list not empty
nodePtr = head;
while
(nodePtr->next)
nodePtr = nodePtr->next;
nodePtr->next =
newNode;
}
}
void LLQ::viewList() const
{
struct node *ptr;
if (head == NULL)
cout << "\nThe
Queue is empty" << endl;
else
{
ptr = head;
cout << "\nCurrent
Queue:\n" << endl;
while (ptr !=
NULL)
{
cout << ptr->character;
ptr = ptr->next;
}
}
cout << endl;
}
bool LLQ::inspectList()
{
bool isValid = true;
node *nodePtr;
nodePtr = head;
if (nodePtr->character != 'a') //checkin
if first element is not 'a'
isValid = false;
else
{
while (nodePtr->next
&& isValid == true) //checking for characters other than
'a' or 'b'
{
if (nodePtr->character != 'a' || nodePtr->character !=
'b')
isValid = false;
nodePtr = nodePtr->next;
}
}
return isValid;
}
LLQ::~LLQ()
{
node *nodePtr; //to traverse the list
node *nextNode; //to point to the next node
nodePtr = head;
while (nodePtr != NULL)
{
//save a pointer to the
next node
nextNode =
nodePtr->next;
//delete the current
node
delete nodePtr;
//position nodePtr at
the next node
nodePtr =
nextNode;
}
}
---------------------------------------------------------------------------
LQ.h
---------------------------------
#ifndef LQ_H
#define LQ_H
#include <iostream>
class LLQ {
private :
struct node
{
char character;
node *next;
};
node *head;
public:
//constructor
LLQ()
{head = NULL;}
//destructor
~LLQ();
//functions
bool is_full() const;
bool is_empty() const;
void remove();
void insert(char);
void viewList() const;
void createList(char);
bool inspectList();
};
#endif
You have to use a h file for class definitions and two (as specified below) cpp...
Purpose: Once you have completed and tested the functionality of your MyStringBuilder class, you will do a rough comparative test to see how long some of the operations take relative to the predefined StringBuilder class and the predefined String class. Details: You will complete a simple simulation to compare the times required for three operations: append(char c) , insert(int loc, char c) and delete(int start, int stop) These methods are defined in the StringBuilder and MyStringBuilder classes, but you will...
Using java Create a simple queue class and a simple stack class. The queue and stack should be implemented as a linked list. Create three functions that utilize these data structures Write a function that opens a text file and reads its contents into a stack of characters. The program should then pop the characters from the stack and save them in a second text file. The order of the characters saved in the second file should be the reverse...
Please write a c++ header file, class implementation file and
main file that does all of the following and meets the requirements
listed below. Also include a Output of your code as to show that
your program works and functions properly.
EXERCISING A DOUBLY-LINKED LIST CLASS
This project consists of two parts, the second of which appears
below. For the first part, write a class that
implements an unordered list abstract data type
using a doubly-linked list with pointers to...
Create a class named Module2. You should submit your source code file (Module2.java). The Module2 class should contain the following data fields and methods (note that all data and methods are for objects unless specified as being for the entire class) Data fields: A String object named firstName A String object named middleName A String object name lastName Methods: A Module2 constructor method that accepts no parameters and initializes the data fields from 1) to empty Strings (e.g., firstName =...
JAVA Implement a MyQueue class which implements a queue using two stacks. private int maxCapacity = 4; private Stack stack1; private Stack stack2; Note: You can use library Stack but you are not allowed to use library Queue and any of its methods Your Queue should not accept null or empty String or space as an input You need to implement the following methods using two stacks (stack1 & stack2) and also you can add more methods as well: public...
DIRECTIONS FOR THE WHOLE PROJECT BELOW BigInt class The purpose of the BigInt class is to solve the problem using short methods that work together to solve the operations of add, subtract multiply and divide. A constructor can call a method called setSignAndRemoveItIfItIsThere(). It receives the string that was sent to the constructor and sets a boolean variable positive to true or false and then returns a string without the sign that can then be processed by the constructor to...
Using C++, create a doubly linked list data structure that stores strings. At a minimum, you must have a List class that contains the list functionality (including an insert function) and a linkable object ("link node") class. For convenience, you may include the data directly or the data may be external to the link node, connected with a reference. You may use an inner class for the LinkNode and/or include the LinkNode class with the List class file if you...
Given java code is below, please use it!
import java.util.Scanner;
public class LA2a {
/**
* Number of digits in a valid value sequence
*/
public static final int SEQ_DIGITS = 10;
/**
* Error for an invalid sequence
* (not correct number of characters
* or not made only of digits)
*/
public static final String ERR_SEQ = "Invalid
sequence";
/**
* Error for...
This lab will give you a practice with both queue and stack ADTs. In this work, you are to determine if an input string is a palindrome. A string of characters is a palindrome if and only if it reads the same forward and backward. Examples: eye, abba, civic, radar, and so on. Sample Output: Please enter a string of characters: abba The given string is a palindrome. Want to examine another string? (y/n): y Please enter a string of...
In C++
Task 3: Use the stack and queue to simulate receiving and transforming data We are creating a system that will convert strings sent over a serial bus one character at a time. The conversion will be from big to little endian or from little to big endian. To simplify this, each character will be considered a word. Little endian will have the lowest address first. Big endian will have the biggest address first. For example (for this lab),...