A queue using a linked list..having troubles with the rest

ok...
this is the assignment ( [http://jessehardesty.com/uploads/p2.JPG] ) picture is kind of big...
I have to have a "queue" class, but I will have to remove some people from the line that are in the middle (which is why i put it in quotes).
this is the queue class I have as of now...
public class Queue
       private static class Node
          int item;
          Node next;
       private Node head = null;  // Points to first Node in the queue.
                                  // The queue is empty when head is null.
       private Node tail = null;  // Points to last Node in the queue.
       void enqueue( int N ) {
             // Add N to the back of the queue.
          Node newTail = new Node();  // A Node to hold the new item.
          newTail.item = N;
          if (head == null) {
                // The queue was empty.  The new Node becomes
                // the only node in the list.  Since it is both
                // the first and last node, both head and tail
                // point to it.
             head = newTail;
             tail = newTail;
          else {
                // The new node becomes the new tail of the list.
                // (The head of the list is unaffected.)
             tail.next = newTail;
             tail = newTail;
       int dequeue() {
              // Remove and return the front item in the queue.
              // Note that this can throw a NullPointerException.
          int firstItem = head.item;
          head = head.next;  // The previous second item is now first.
          if (head == null) {
                // The queue has become empty.  The Node that was
                // deleted was the tail as well as the head of the
                // list, so now there is no tail.  (Actually, the
                // class would work fine without this step.)
             tail = null;
          return firstItem;
       boolean isEmpty() {
              // Return true if the queue is empty.
          return (head == null);
    }my problem is that I don't know how to go about doing the units of time. We are given a data file with the time of arrival, length of transaction, amt bought, and money spent.
it's kind of long or I'd post it...but they are all ints. I'll have to read from the file. My problem (for now) is that I don't know what kind of loop to do, and how to read them in correctly...it is 4 ints per line in the file, spaces in between of course. What kind of loop should be used?...and how do I go about keeping track of all the "people" in line without using 40+ counters (one for each "person").
thanks, and hopefully that makes some sense.
Edited by: Taco_John on Mar 23, 2008 5:08 PM

* Queue.java
* Created on March 24, 2008, 3:12 PM
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
package test;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;
* @author Rajesh
public class Queue <T>
private static class Node<T>
int item;
int custArrive;
int transTime;
int amtBought;
int dollSpent;
Node next;
private Node head, tail;
private int count;
public Queue()
count = 0;
head = tail = null;
public void enqueue( T element ,int a,int b,int c,int d) {
// Add N to the back of the queue.
Node<T> newTail = new Node<T>(); // A Node to hold the new item.
if (head == null)
head = newTail;
head.custArrive = a;
head.transTime = b;
head.amtBought = c;
head.dollSpent = d; tail = newTail;
else
tail.next = newTail;
tail = newTail;
tail.custArrive = a;
tail.transTime = b;
tail.amtBought = c;
tail.dollSpent = d;
private int dequeue()
int firstItem = head.item;
head = head.next; // The previous second item is now first.
if (head == null)
tail = null;
return firstItem;
public void showElement()
Node<T> newTail = new Node<T>();
for(newTail=head; ;newTail=newTail.next)
System.out.println(""+newTail.custArrive+"\t"+newTail.transTime+"\t"+newTail.amtBought+"\t"+newTail.dollSpent);
if(newTail == tail)
break;
*}* boolean isEmpty()
// Return true if the queue is empty.
return (head == null);
public static void main (String [] args)throws IOException
int custArrive;
int transTime;
int amtBought;
int moneySpent;
FileReader infile = new FileReader ("C:/Documents and Settings/pb46627/Desktop/prog3.txt");
Scanner fin = new Scanner (infile);
Queue myQueue = new Queue();
int i=0;
while (fin.hasNextInt())
custArrive = fin.nextInt();
transTime = fin.nextInt();
amtBought = fin.nextInt();
moneySpent = fin.nextInt();
myQueue.enqueue(i++,custArrive,transTime,amtBought,moneySpent);
*//fin.next();*
i++;
myQueue.showElement();
*// System.out.println(""+myQueue.count);*
And this is the Input file i used.......
10     20     30     40
50     60     70      80
90     100     110     120
prog3.txt
Now you can able to see the output as
10     20     30     40
50     60     70      80
90     100     110     120
i use BOLD FONT_ , indicates my changes
just try with this and comment.......
i'm waiting for your reply.....
thank you
rajesh

Similar Messages

  • Using iphone 5c. Having trouble with the built in dictionary. I need to download japanese to english dictionary every time when I want to use it. English to english dictionary works perfectly.

    I am using iphone 5c with ios version 7.0.4.
    language- English
    I am having trouble to use Japanese to English dictionary in iBooks.
    Although I can use oxford english to english dictionary.
    But cant use Japanese to English dictionary or Japanese dictionary in it.
    When I search any English meaning for Japanese word in iBooks ,
    a page show up with "No definition found" in middle of the screen
    and "Mange" "Search Web" on two different lower corner side of the screen.
    If I download the dictionary from "manage" I can use that before locking the screen..
    When I unlock the screen and try to use Japanese to English dictionary again in IBooks it does not work.

    I think this is a bug apple needs to fix.  Tell them via
    http://www.apple.com/feedback

  • I'm having trouble with the folder "Automatically add" function. She opens a folder "not added". My machine is a Vaio with Windows 7 home basic antivirus using Microsoft. Regards.

    I'm having trouble with the folder "Automatically add" function. She opens a folder "not added". My machine is a Vaio with Windows 7 home basic antivirus using Microsoft. Regards.

    Its a 64 bits.

  • Having trouble with the messages on mac my friends using it are coming not registered when i try to send them a message

    having trouble with the messages on mac my friends using it are coming not registered when i try to send them a message

    That's probably because they're not registered.
    Messages only works if your friend has an iphone.
    There is a workaround that can work, though.
    set up an AIM account online.
    in System preferences > mail, contacts, and calendars, enter your new AIM account.
    in Contacts, on your friend's contact card, look for AIM. Enter their phone number right before that, with a +1 before it, and the area code:  i.e., +11234567899.
    This doesn't always work. Their cellular carrier has to cooperate with AIM. Some do, some don't. If it doesn't work, tell your friend to get an iPhone.

  • I have a factory unlocked 4s I'm haveing trouble with the mms withI have a  straight talk I'm useing the sim card swap with tmoblil sim card I'm following the insructions but it works for a while and then its gone. I've set the settings at least ten times

    I have a factory unlocked 4s I'm having trouble with the mms with straight talk I've been useing the sim swap system with tmobile i have put the settings in five times. The setting won't stay it works for a while and then it's gone. I'm not in a good coverage area but when i put the settings in i make sure i'm getting a good signal or near wifi. any suggestions would be great.

        Congrats on your recent upgrade actionkatie! I am sorry to learn of the difficulties you are experiencing with your Samsung Galaxy S4. Let's get to the bottom of this because we want you to love your phone.
    I understand you have done all necessary troubleshooting steps that should have enabled you to send messages to iPhone users without them having to disable iMessage. Have you tried contacting Apple Support regarding the inability to send a text message to iPhone users? Apple can be reached at (800) 275-2273.
    In addition, do you get a certain error message when your WiFi stops working? Have you verifed that Auto Switch network is disabled? To disable this setting simply to go Settings > Wi-Fi > Tap the Menu Key(to the left of the home button) > Select Advanced and it is called `Auto network switch. If you are still experiencing difficulties, please feel free to reach out to us for further assistance.
    Thank You,
    MichelleL_VZW
    VZW Support
    Follow us on Twitter @VZWSUPPORT

  • I am having trouble with the reminders app for iPad mini on iOS 7. When I. hit add list it doesn't add a list. I've tried everything. Thank you.

    I am having trouble with the reminders app for iPad mini on iOS 7. When I. hit add list it doesn't add a list. I've tried everything. Thank you.

    Device not recognized by iTune
    http://support.apple.com/kb/TS1591

  • I HAVE A MAC G5 WITH V10.4 TIGER OS, I AM HAVING TROUBLE WITH THE LETTER "N" ONLY WHEN I USE CAPS AND SHIFT KEYS DOSE IT TYPE THE LETTER "N"SE

    HAVE A MAC G5 WITH V10.4 TIGER OS, I AM HAVING TROUBLE WITH THE LETTER "N" ONLY WHEN I USE CAPS AND SHIFT KEYS DOSE IT TYPE THE LETTER "N". I HAVE CONNECTED A NEW KEYBOARD BUT THE PROBLEM STILL EXIST. WHAT ELSE CAN I DO?

    You might look at "Keyboard Shortcuts" in the Keyboard and Mouse preference pane and see if somehow the lower case n has been inadvertently assigned to something.
    Probably the best solution would be to click the "Restore Defaults" button.

  • Having trouble with the sound!!!

    Recently I'm having trouble with the way the music played by the iTunes sounds! I first thought I have moved the equalizer's settings but I didn't. Music sounds funny with echo.... I'm sure that's a problem of the iTunes because I have played the same song using Windows Media player and it sounds fine! Can someone help me please???!!!!

    Can I just check.
    You went to System Preferences (The Square grey icon with an Apple and Lightswitch or from the Blue apple menu top left) ?
    Form the List of Preference Panes you choose Sound far right of the second row ?
    And the Sound Effects tab in there ?
    There should be a volume control for them in there and it need moving to the right.
    10:52 PM Monday; January 15, 2007

  • HT203433 I'm having trouble with the purchased stickers.

    Dear iTunes Store Help Center
         I'm having trouble with the purchased stickers. I purchased LINE Sticker, Doraemon & Doremi. But Sticker are not show in my Sticker history and can not use sticker (Doremi). Please advise me what to do.
    My registration details:
    - Country : Thailand
    รายการ
    ผู้พัฒนา
    ประเภท
    ราคาต่อ หน่วย
    LINE, Doraemon & Dorami
    รายงานปัญหา
    NAVER JAPAN
    การซื้อผ่าน App
    $1.99
    LINE, Doraemon
    รายงานปัญหา
    NAVER JAPAN
    การซื้อผ่าน App
    $1.99
    ยอดรวมของใบสั่ง:
    $3.98
    <Personal Information Edited by Host>

    Most of the people on these public forums, including myself, are fellow users - you're not talking to iTunes Support here. I've asked the hosts to remove your email address from your post.
    Have you tried the help on the developer's site : https://line.naver.jp/help/iphone/en/serviceId/10155/sp ?
    If you haven't received the items then you contact iTunes Support via this page : http://www.apple.com/support/itunes/contact/ - click on Contact iTunes Store Support on the right-hand side of the page, then Purchases, Billing & Redemption

  • I'm having trouble with the MTS MT2S convertor.

    I’m having trouble with the MTS MT2S convertor. On my video camera (I have a Panasonic HC-V500 full HD 1920x1080) I’ve recorded in HD and when I use the MTS convertor to change the file type I select the HD option it’s a quicktime .mov file type and when it has finished converting the quality of the video goes to a lower quality and the colours aren’t vibrant like shown on the original recording on my camera. It also looks slightly grainy. So my question is which HD file type should I be choosing? As I no there’s a few but unsure which is best to use. I have also changed quality to original and didn’t make a difference on the quicktime .mov file type. I wasn’t sure if theres anything else on there I’m meant to be adjusting? As the software didn’t come with any instructions on how to use it. Just to mention i upload my videos to youtube so i want them to be in HD but i use iMovie as my editing software before i upload to youtube and i no avi file format isn't supported in iMovie.

    Its a 64 bits.

  • Having trouble with the highlights

    I have Samsung Galaxy S3 with Android 4:3
    I am having trouble with the highlight feature. When I highlight a word or a sentence Adobe Reader highlights it without a problem yet I cannot see all the highlighted parts of the pdf file as a list. Thus I cannot jump to different highlighted parts of the document.
    When I bookmark a page for example I can see all the bookmarked pages under a list so it allows me to jump through. 
    How can see and jump between all highlights and annotations? Thanks

    Adobe Reader presently doesn't allow you to see all the highlighted text at a single place. We have noted down your request, and will update you if it becomes available in one of our future releases.

  • Having trouble with the most simple of things: Static IP

    I am having trouble with the most simple of things: Static IP.
    I am working in Windows Server 2008 R2 SP1.
    "Control Panel\Network and Internet\Network and Sharing Center\Local Area Connections>Properties>Internet Protocol Version 4 (TCP/IPv4) and Internet Protocol Version 6 (TCP/IPv6)"
    IPv4: I have went to "ipconfig /all" and found the "preferred" IP Address and the Default Gateway. 
    Assign DNS Servers?
    IPv6: I used "netsh interface ipv6 show address level=verbose" and found 3 usable IPv6 IPs.
    Assign IP Address, Default Gateway and DNS Servers?

    What is the question?
    Regards, Dave Patrick ....
    Microsoft Certified Professional
    Microsoft MVP [Windows]
    Disclaimer: This posting is provided "AS IS" with no warranties or guarantees , and confers no rights.

  • I'm having trouble with the install of Adobe digital editions

    I'm having trouble with the install of Adobe digital editions, how can we fix this? It will begin to dowload it says complete but stops there, no other prompts and if you click the close button it appears that it begins to delete itself. How can i fix this issue?

    Hi,
    It would be great, if you provide us with the environment where you are trying the install the ADE.
    For Example,
    - ADE version
    - Operating System
    - Anti-Virus you are using.
    - did you logged in as Admin or user on your computer.
    (*any error message you are able to locate/view  from Event Viewer- If using Windows OS)
    Regards,
    Yuvraj.

  • I am having trouble with the ipad2 freezing up causing me to restart the tablet.  How can I fix this?

    I am having trouble with the ipad2 freezing up causing me to restart the tablet.  How can I fix this?

    Doubt it is a Hardware issue...
    If the Reset and the Restart have not Resolved the Issue...
    Then the Next Step is a Restore...
    Restore...
    1: Connect the device to your computer and open iTunes.
    2: If the device appears in iTunes, select and click Restore on the Summary pane.
    3: If the device doesn't appear in iTunes, try using the steps in this article to force the device into recovery mode.
    From Here
    Unresponsive iPad
    http://support.apple.com/kb/TS3281

  • Having trouble with the str()function

    I'm having trouble with the str() function. The first parameter is the value and I want to set the format but I keep getting an error. I do it like this. str(locals.array[8]-locals.array[9],"%$.6f"). I get a runtime error, so I tried to remove the "" but now the I get a syntax error.

    Hi,
    Can not see a problem with your statement.
    I have attached a TS2.0.1 example using you expression.
    Regards
    Ray Farmer
    Regards
    Ray Farmer
    Attachments:
    Sequence_File1.seq ‏20 KB

Maybe you are looking for

  • Memory on GNB MAX

    Hi there, i have a queestion about memory type for the GNB MAX, in the specifications it says that the type of memory should be 2100 (266), but can i use another newer? for example one memory at 2700? i know that maybe the performance is not the same

  • What kind of computer specs are required to smoothly run CS5 and future versions?

    Hello, I'm in search of a new laptop for running CS5. I checked the Adobe site for system specs (http://www.adobe.com/products/creativesuite/design/tech-specs.html) and they look ridiculous -- I stopped reading at 1 GB RAM... So my question is what s

  • TS3276 Trouble with Mail using Lion

    I just converted to Lion and am not receiving any emails, although connection doctor shows all accounts to be green.  What am I doing wrong?

  • How to compile an .air app from the ADT command line?

    Hi, I would like to compile an .air app from the ADT command line. Does anybody have an example? I don't know how to add the AIR SDK path and a folder to it. Is there a generator for the command line availabble? Thanks

  • Scheduled Tasks

    We are running CF 7.02 on windows server 2003 We have a number of tasks that are scheduled to run throughout the night and have been running this way for several years. Yesterday our CF server hung. While looking through the server logs to troublesho