Create Program Which Inherit Stack And Queue From A Linked List Class

Nov 18, 2014

I want to create java program in which i want to inherit stack and queue from a linked list class and also make infix to postfix inherit from stack and periority queue from queue class.Ho can i make this program.

View Replies


ADVERTISEMENT

Linked List Queue ToString Method

Oct 21, 2014

So I have to write all the methods for a LinkedListQueue. I've got isEmpty, enqueue and dequeue working correctly (I think) but I'm having trouble with the toString method. I tried to do it recursively and it works if there is only one element in the list, but with multiple elements it throws a StackOverflowerror exception. I've tried it multiple different ways, but I can't seem to figure out how to print it out with out clearing everything. We haven't been taught StringBuilder or .append yet, which I saw a lot of as I was looking for solutions, so I can't use those.

public class LinkedQueue<T>
{
protected LLNode<T> front; // reference to the front of this queue
protected LLNode<T> rear; // reference to the rear of this queue
private T info;
public LinkedQueue()
{
front = null;
rear = null;

[Code] ....

and this is the ITD used with it, for some reason it has the "empty the queue" function as a choice but we weren't assigned that function, so just ignore it.

import java.util.Scanner;
public class ITDLinkedQueue
{
public static void displayMenu()
{
System.out.println("(1) display menu");
System.out.println("(2) check isEmpty");
System.out.println("(3) enqueue");
System.out.println("(4) dequeue");

[Code] ....

View Replies View Related

Program Used To Implement Palindrome String Of Using Stack And Queue

Jan 8, 2015

this program used to implement palindrome String of using stack and queue.i wont to enter string by scanner how can i chang it ??????

class Palindrom_homwork1{
int top=-1;
int rear=-1;
int front=-1;
int max=3;
int max1=3;
char array[]=new char[max];
char array1[]=new char[max1];

[code]....

View Replies View Related

Dequeue Of Queue Implemented Using Circular Singly Linked List With No Tail Reference

Oct 27, 2014

So I'm trying to build a queue, first in first out, (so add to the head remove from the end) using a linked list for use in another program, I'm having a problem dequeueing where the program seems to run indefinitely without giving an answer, so my suspicion is its caught in a while loop but how and why I can't figure out.

public class CircularQueuelist {
private Node head = null;
private int size = 0;
private class Node
{
int data;
Node next;
 
[Code] ....

My logic seems sound, I basically look for when the second node over from the current one I'm on is a reference to the head, and then skip the one in front of it using setting currents. next link to current.next = head, severing the link to the last node.

This is what my driver looks like, I enqueue items 1-10 and then use the iterator to make sure it worked out fine and check size, its when I dequeue that I run into a problem, the program runs indefinitely.

public class Queuetest {
public static void main(String[]args)
{
CircularQueuelist test = new CircularQueuelist();
for (int count = 0; count < 10; count ++)

[Code] ....

View Replies View Related

Method That Print Data Of Single Linked List Backward Using Stack

Apr 23, 2015

I am trying out solving the question but i am stuck.The problem is to write a method that print data of single linked list backward using stack.The question is as follow

public class Stack{
public boolean isEmpty(){};
public void push(int n){};
public int peek(){};
public int pop(){};
}

public class node{
int data;
node next;
}

public class list{
node first;
}

View Replies View Related

List Interface Class That Has Operations For Linked List And LList Class

Oct 6, 2014

I have this ListInterface class that has operations for my linked list and a LList class. The Llist and ListInterface classes are perfect. My job is to create a driver, or a demo class that showcases these operations. That being said, heres the driver so far:

import java.util.*;
public abstract class DriverWilson implements ListInterface
{
public static void main(String[] args)
{

LList a = new LList();

[code]....

View Replies View Related

Can't Get GUI Program To Print Out Queue List

Apr 11, 2014

I have been working on this Java Gui program and i cant get it to print to the textbox correctly.i originally had it displayed in a dialog window but it would print one integer a time in a seperate window.

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.lang.*;
import java.io.*;

[code]....

View Replies View Related

Comparable Class - Create Priority Queue For Airline Passengers

Oct 9, 2014

My assignment was to create a priority queue for Airline Passengers. Here is what I have done so far:

//Driver

package priorityqueuestandby; 
import java.util.NoSuchElementException;
import javax.swing.JOptionPane;
public class PriorityQueueStandBy {
public static void main(String[] args) {

[Code] .....

So the part that I cant figure out is:

When a standby passenger is to be enqueued into the priority queue, it must be done so that at the moment of each dequeue operation, the item at the head of the queue is the standby passenger with the longest longevity, and also so that passengers with the same longevity are dequeued in a first-come-first-served fashion.

he says that we need to "Make your program so that it extends Comparable and implements the compareTo() method properly..."

So I was looking at the Comparable class and I could't find a compareTo() method... I am not confident I know how extends works either. I am assuming I need a new class if I am going to be extending another class. Right now I am taking in longevity as a String and converting it to an int because my last ditch effort is going to be to set up a loop that will organize longevity into a/an circular array based on the size of the incoming integer.

View Replies View Related

How To Remove / Add Instances Of Class In Linked List

Dec 11, 2014

I have to write a test class for a Contacts class called ContactTest and store the instances of Contacts created into a LinkedList.The ContactTest class should implement the addition andremoval of contacts to the Linked List and display its contents.

So far I have this, which stores the information entered into a Linked List, the problem is I don't know how I go about doing the addition and removal part.

Contacts Class

public class Contacts implements InterfaceContacts {
String fname;
String lname;
String phone;
String email;
//constructors
public Contacts( ){
this("****", "****", "****", "****");

[Code] ....

View Replies View Related

Singly-linked List Program Challenges

Oct 22, 2014

read a text file that has some polynomials in a specific format and perform an arithmetic expression. This needs to be done using a singly-linked list to store the coefficients of the polynomials. There needs to be two methods, one that adds the two polynomials and one to multiply them. So for example suppose i had the following set of polynomials in the text file:

2+x2-3x3 and 1-x-2x2+3x3

these are represented by 2, 0, 1, -3 and 1, -1, -2, 3 respectively. The of the two polynomials is: 3-x-x2 which is represented as: 3, -1, -1

The product of the two polynomials is: 2-2x-3x2+2x3+x4+9x5-9x6

My code is just echoing the data in the text file and not actually doing any arithmetic.

import java.io.*;
import java.util.Scanner;
class Node {
public int digi1;
public int digi2;
public Node nxt;

[code]....

View Replies View Related

Finding Palindromes From Stack And Queue?

Apr 30, 2015

I'm trying to create a class that takes an String from a Stack and checking if it's a palindrome than taking a another String from a queue and checking if that is also a palindrome.

import java.util.Stack;
public class Palindrome {
 public static void main(String[] args) {
// TODO Auto-generated method stub
 String enteredLine;
int leftStack, rightStack;
int leftQueue, rightQueue; 
PalinedromeArray stack1 = new PalinedromeArray();

[code]....

View Replies View Related

Finding Road With Stack Or Queue

May 2, 2014

I have to make code about finding road with Stack or Queue. At first, I tried to make it in this way...

Java Code:

//public class QueueMain {
public static void main(String[] args){
int [][] arr = {{0, 0, 1, 0, 0, 1, 0, 0, 0}, //p
{0, 0, 0, 0, 0, 0, 1, 0, 0},//q
{0, 0, 0, 0, 0, 0, 1, 0, 0},//r
{0, 0, 0, 0, 1, 0, 0, 0, 0},//s
{0, 0, 0, 0, 0, 1, 0, 0, 0},//t
{0, 0, 0, 1, 0, 0, 0, 1, 0},//w
{0, 0, 0, 0, 0, 0, 0, 0, 0},//x
{0, 0, 1, 0, 0, 0, 0, 0, 1},//y
{0, 0, 0, 0, 0, 0, 0, 0, 0}};//z
String [] add = {"P", "Q", "R", "S", "T", "W", "X", "Y", "Z"};
int originnumber = 0;
int destinationnumber = 8;

[Code] ....

But it doesn't work at all. I tried to put visited address into array<mark>... but it didn't work.

View Replies View Related

Writing Method Symmetric Using Stack And Queue

Apr 19, 2015

The question is write to a method symmetric that accepts a stack of integers as a parameter and replaces the stack contents with itself plus a symmetrical version of itself (the same elements in the opposite order).

For example, suppose a variable s stores the following elements:
bottom [10, 50, 19, 54, 30, 67] top

After a call of symmetric(s),the stack would store the following elements
bottom [10, 50, 19, 54, 30, 67, 67, 30, 54, 19, 50, 10] top

Note that the symmetric version is added on to the top of what was originally in the stack. The bottom half of the stack contains the original numbers in the same order.

If your method is passed an empty stack, the result should be an empty stack.
If your method is passed a null stack, your method should throw an IllegalArgumentException.

a) Write the method symmetric using one temporary stack and one temporary queue.
/> Re-write the method using only one temporary Queue.

What I have done so far is

public static Stack symmetric(Stack s1){
Stack s2 =new Stack();
int theTop=0;
if(s1.isEmpty()){
return s1;

[Code] .....

Its not working.

View Replies View Related

Java Program To Implement A Single Linked List Structure

Jul 27, 2014

I'm trying to build a program that contains the ability to:

(1) insert new node at head,
(2) print out contents of the list in order,
(3) remove first node from head,
(4) remove last node from tail,
(5) find a target value,
(6) give total number of occurrences of a target value, and
(7) give total number of items in list.

The areas I'm struggling with implementing are: (

- remove from tail - I know how to find the final node but I can't quite figure out how to set it to null since its initial type is an integer.
- find a target value - how to make the parameters quite workout so the user can simply input an integer value.
- The solution is probably really simple but I can't figure out how to print out the results of these methods when I call them.

public class Node
{
private int data;
private Node link;
// Node Constructor 1
public Node()
{
data = 0;
link = null;

[code]....

View Replies View Related

Method Receives Queue As Parameter - How To Print A Stack

Nov 4, 2014

I'm doing an assignment where a method receives a Queue as a parameter then convert it into a stack, I made it but now I want to try it in my main, but how can I do this? there's no toString and I cant use a for loop because I'm using a queue and not an array. This is the head of my method:

public static void QueueStack(Queue<Integer> q){

View Replies View Related

Write A Java Program To Store Employee Information In A Linked List

May 12, 2015

Write a java program to store employee information in a linked list, the program should implement the following functions:

The program should display the list of functions, and ask the user to enter the number of function that he/she wants to do, then perform the function as it is required in the previous table.

import java.util.*;
public class Employee {
Scanner in = new Scanner(System.in);
String Name;
String Address;
String Department;
int ID;
int Salary;

[code]....

this is my out put

Please choose a number:
1-Add a new employee
2-Update employee's info
3-Remove employee's info
4-Exit
1
Enter name:
Enter address:
2
Enter department:
3
Enter ID:
4
Enter salary:

now:

1- why are not my adding coming out in the output only the Enter name & Enter address ??

2- how can I add names and ID's and information to test that program

View Replies View Related

Why Interface Inherit All Non Final Methods From Object Class

Jan 8, 2014

why interfaces inherit prototype of all the non final methods of the object class in itself? Object class is parent class of all the class and Interface is not the class.

View Replies View Related

Remove All Numbers From Queue And Push Onto Stack Until Operator Is Reached - Null Pointer Exception

Apr 26, 2015

This method keeps throwing a NullPointerException. Not only that, but its not doing what I want it to do.

Heres the code:

/*
Remove all the numbers from the queue and push onto the stack until an operator is reached
*/

private static void processQueue() {
// Check what is at the front of the queue. If an operator is found or the queue is empty, exit method.
while(queue.front() != null || !queue.front().equals("*") || !queue.front().equals("/") || !queue.front().equals("%")
|| !queue.front().equals("+") || !queue.front().equals("-"))
{
stack.push(queue.removeFront()); // push the operand onto the stack
}
}

Here is the method that calls the processQueue() method

/*
Process the mathematical expression using a stack and a queue
*/
private static double processExpression() {
// insert all elements from the stack to the queue for processing
while(stack.top() != null) {
queue.insertBack(stack.pop());

[Code] .....

View Replies View Related

Linked Stack With Directory Won't Print

Apr 14, 2014

Im trying to create a linked stack that will hold the starting directory to the current directory, so that when i finish a directory it would go back to the parent. as i go through the files in a directory and find a child directory, i have to stack current directory and process the child directory, when thats done, pop the parent from the stack and continue processing it. Here is my code:

//import io File and ioexception
import java.io.File;
import java.io.IOException;

/*create class that will take a path to a directory, print the name of the argument directory, print the name of each file and directory in argument directory. Prints the directory name and each file and directory inside*/

public class dirStackPrint

[Code] .....

when I run the program, nothing prints, why is that? I'm having trouble understanding the processing of the top, push and pop functions, i have them in my code but they don't seem to be working as they should?

View Replies View Related

Sort Linked List Through The Nodes Of List - Data Of Calling Object

Feb 14, 2014

I have some class called sorted to sort the linked list through the nodes of the list. and other class to test this ability, i made object of the sort class called "list1" and insert the values to the linked list.

If i make other object called "list2" and want to merge those two lists by using method merge in sort class. And wrote code of

list1.merge(list2);

How can the merge method in sort class know the values of list1 that called it as this object is created in other class.

View Replies View Related

Linked List Implementation Of List Interface?

Oct 5, 2013

So we have an assignment regarding a linked list implementation of a given list interface.

In my list interface, the method contains(T anEntry) is defined.

In the LList implementation, contains is already implemented as part of getting the core methods in.

Now I am being tasked with the following:

Provide a second implementation of the method contains2(T anEntry) that calls a private recursive method

Private boolean contains (T anEntry, Node startNode) that returns whether the list that starts at startNode contains the entry anEntry.

I've written the private recursive method already. That's not an issue (at least not right now).

But what I don't understand is how startNode is supposed to be populated when this private contains method is called from the public contains2 method? contains2 only takes one parameter: anEntry. the private method takes two parameters: anEntry and startNode. How am i supposed to provide startNode when I am calling contains2?

View Replies View Related

How To Create A Driver Program That Invokes A Class

May 13, 2014

Assignment:

Create a class; call it Lab4a that will have one method called pull. This method does not return anything and requires no parameters.

-In the method, create three random integers in the range 1 to 7. The method will then display the three numbers to the terminal window.

-Now create a driver program, called SlotMachine, to invoke the pull method of the Lab4a class.

-As a refresher, you will have a main method in the driver class that will create an object of Lab4a and then use the only method of this object.

-In your driver program, invoke the roll method 10 times.

-See the back of this lab for an example of the output.

This is what I have so far.

Slot machine

import java.util.Random;
public class Lab4a {
public static void main (String[]args) {
Random pull=new Random();

[code]....

View Replies View Related

Unable To Create A Program For Class Using Two Dimensional Arrays

Dec 6, 2014

I am trying to create a program for class the uses two dimensional arrays. I am stuck on the second step that states Use two parallel arrays. One is a two-dimensional array -- a row of this array will hold six values in this order: [0] number of hours worked, [1] hourly pay rate, [2] gross pay, [3] net pay, [4] federal withholding, and [5] state withholding.

This is what I have so far:

Java Code:

double [][] data = new double [30][6];
String [] names = new String [30];
String str = null;
String detail = null;
int n = input(data, names, inputFile); mh_sh_highlight_all('java');
(there's more but i don't believe it pertains to this question)

My question is how would I create this array. Or, is that right above? I've searched online and in my book and I just don't understand.

View Replies View Related

Inserting A Set Into Linked List?

Mar 21, 2014

What I'm supposed to do is make a method to insert a set of Tiles to the list,i.e.,a detour(make sure that the inserted detouris compatible with thecurrent path so that the resultingpathdoesnot have any gaps). But I'm confused on how to go about doing it. I was thinking of maybe just adding 1 to the current Node.

import java.io.File;
import java.io.FileNotFoundException;
import java.util.List;
import java.util.Scanner;
public class Path {
static Tile startTile;

[code].....

View Replies View Related

Dynamic Linked List

Jan 30, 2014

I'm trying to implement an Office class that contains an inner class: WorkerNode. The WorkerNode class has a name attribute (String) and WorkerNode attributes for boss, peer and subordinate. The attributes of Office are manager and current which are WorkerNode references. The manager refers to the entry point of the structure and current is the current node in the structure. For simplicity, i'm going to try to limit it to 3 levels and assume that the names are unique. I've put together a Office class that containing main and provided the code I've worked on so far.

public class Office {
public static void main(String[] args) {
String name=Input.getString("input the manager's name: ");
Office office=new Office(name);
int option;

[code]....

View Replies View Related

Linked List Sorting

Apr 20, 2014

I have made a node class and im trying to implement a sorting method. I must use a selection sort but with specific instructions: "Your method should not need to use the new operator since it is just moving nodes from one list to another( not creating new nodes)

this is my current implementation ..but i am instantiating new object..

public class NodeInt
{
private int data;
private NodeInt next = null;
public NodeInt(){}
//precondition:
//postcondition:
public NodeInt(int data, NodeInt next)
{
this.data = data;
this.next = next;

[code]....

edit: this is the part that worked but i had it commented out so i have the previous and current declared above but didnt copy.

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved