I have a Queue class (containing a LinkedList plus a few other variables and stats for my project), which works fine with the standard LinkedList, but I'm trying to add my own code for MyLinkedList.
However, I keep getting a NullPointerException at my remove method.
public class MyLinkedList<T> {
Node head;
public MyLinkedList() {
head = null;
}
public class Node {
T contents;
Node nextNode;
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.
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.
I'm working on a lab for my class. I need to create a Priority Queue in Java using an array list. The kicker is that each node has to have a "handle" which is just an object which contains the index of of the node that it's associated with. I know that sounds weird but we have to implement it this way. Anyway, my priority queue seem to work fine except the handle values apparently aren't updating correctly because I fail the handle test. Also, I run into problems with handles only after extractMin() is called, so I figured the problem would be somewhere in that method but I've been through it a million times and it looks good to me.
Here is my Priority Queue Class:
package lab3; import java.util.ArrayList; /** * A priority queue class supporting operations needed for * Dijkstra's algorithm. */ class PriorityQueue<T> { final static int INF = 1000000000; ArrayList<PQNode<T>> queue;
[Code] ....
I can post the tests too but I don't know if that would do much good. Just know that the queue works as is should, but the handles don't point to the right nodes after extractMin() is utilized.
I have just begin to understand collections in Java. I read about the differences between LinkedList and ArrayList but have several doubts on it. I have mentioned them below
1) Why retrieving in ArrayList is faster then LinkedList?. Since both have the get method how does performance differ?.
2) How does re-sizing happens internally in ArrayList when a item is added or removed?. How slow this is compared to the pointer re-shuffling in LinkedList when a item is added or removed?.
My remove(item E) method is working fine if I remove an item that is in the list. However, it has an error when I try to remove an item which is not on the list!
Linked List Class
import java.util.NoSuchElementException;
public class LinkedList<E> { private Node<E> head; // head node of the list private int size = 0; // number of elements that have been added to the list // Returns the element at a specific list index. // Big-O: O(n) (due to the nodeAt call, which must traverse the list) public E get(int index)
I'm doing LinkedList at the moment and I'm having a bit of trouble with my assignment. The part I'm struggling with is remove an employee from a training course (as specified by their employee number),
what I'm confused about is iterating through the linked list to find the employee we're looking for. What I would do in this situation if I was using an array list is
for(Employee emp : myList) { if(emp.getEmployeeNumber().equals(searchedNumber)) { remove from training course.. break; } }
"Can only iterate over an array or an instance of java.lang.Iterable" is what it is telling me, and I can't figure out why/how its done differently for linked lists.
Okay, I'm having a problem with my LinkedList. When I run the driver program it's telling me that I have no "add" method and I don't know what's going on.
Driver Program:
public class TestLinkedList { public static void main(String[] args) { MyLinkedList<String> L = new MyLinkedList<String>(); L.add("Browns"); L.add("Ravens"); L.add("Steelers");
I can't figured out why it's keep giving me error when I tried to add i to the linkedlist. I tried changing it to other numbers but keep giving me nullExceptionPointer.
public static void subset(double[] weight, double[] value, int start) { double sumWeights = 0; for(int i = start; i<weight.length; i++){ if(sumWeights+weight[i]>L){ continue;
I am getting "Type safety: Unchecked cast from Object to LinkedList<EventData>" in eclipse for a piece of code stated below
public LinkedList<EventData> loadFromFile(File file) { queue=new LinkedList<EventData>(); //Some piece of code return (LinkedList<EventData>)queue.clone(); //--->getting warning here }
I know that because clone() method is returning Object, hence compiler doesn't have type information that's why showing warning. I don't want to suppress this warning instead i want to fix it.
i want to write a class in such a way that i should get the current execution time of another class which is running. I searched in net but it shows only how to calculate the time duration of the current class which is running. But as per my way, i need the execution time of one class from another class. How to do this ?
Is it possible to define the same message driven bean as a listener to different queues?
The goal being to define different redelivery configuration for different kind of messages, but handle them all through a single deployment MDB for unity/entity purposes.
The other option is to have many MDBs targeted to the same source code.
I am working on a calculator for Android.To make sure the application I am developing works with multiple operations (in the correct order) I decided to use ANTLR as part of my Java coding of the calculator. So in a separate file (.g4 file), I must declare the format of the expression.
After which I need to include the ANTLR class library in my Java Class. Then I believe I need to call a set of functions such as createLexerInterpreter and createParserInterpreter, but I am not sure. I will be having an algorithm string that will need to be parsed, such as " 3+4*5+8*9+(5/6) ".
I will give an example below of what I am talking about. in C++ I know I would need a copy constructor because I would be pointing blindly in the heap if I deleted a object in the struct.
We have a Class/struct animal and three animals in that class/struct, a dog, a cat and a cow. Each animal has a baby and then I will give the animal a name in main. But if I delete one of the dogs puppies because I sold him wouldn't I being pointing off in the heap and have a leak?
Also since Java doesn't have structs can I put a class inside a class?
leaveQ method does not work..To see the other files related to these code click here:(Its a dropbox location) URL....Java Code:
public class CustomerQ { private int MaxLength; private int totalCustomers;//assuming #of customers served int Qlength; Customer cus; LinkedList4Q cus4Q;
I am doing a bank queue simulator program which will figure what will happen in 100 minute where 0 to 2 customers comes every minute. 3 counters will handle these customers each counter will poll the customer after 3 minutes.my problem is queue.poll()is not working in counter method and it is adding null values to the queue in the same method. when i add while customers.isEmpty(); the program will not work i do not know why
package dataalgo; import java.util.LinkedList; import java.util.PriorityQueue; import java.util.Queue; import java.util.Random; public class customer {
import java.util.*; public class DoubleEndedQueueImplHW22 { ArrayList<Integer> deque = new ArrayList<Integer>(); public void insertFront(int a){ System.out.println("adding at front: "+a); deque.add(0,a); System.out.println(deque);
The following codes shows an implementation of an enqueue function of a FIFO immutable queue, and the output result shows the String "c".
I don't understand why since I expected it should be null.
The head and the tail of an ImmutableQueue Object are two separate queue, and each time I call the enqueue function, it just return a new object with a new tail, however, the head is not modified except the first two times I call the function.
Therefore, I expected head.next.next should be a null element, but the result is not like that.
public class ImmutableQueue<E> { private int size =0; public Queue<E> head; public Queue<E> tail; public ImmutableQueue(){} private ImmutableQueue(Queue<E> hd, Queue<E> tl){ head=hd; tail=tl;
I have a class "ExecuteJob" which has Print Q in the form of Priority Q.
You can keep adding job to the Q by calling one of the method in the class. However, and object cant do things simultaneity can it? While im adding a new job to the print queue, can it be executing and existing job in the print Q.
To achieve that, I would need to implement process and threads? I believe am I right? So that adding a job is independent to being removed?
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();