Results 1 to 3 of 3
  1. #1
    wesgarner is offline Member
    Join Date
    Sep 2009
    Posts
    2
    Rep Power
    0

    Default Help with LinkedList<AnyType>

    Here is my code for a DoubleEndedPriorityQueue (it is for a class, but I am having trouble added an item to the LinkedList)
    I am getting these errors:
    DoubleEndedPriorityQueue.java:48: cannot find symbol
    symbol : method add(int,AnyType)
    location: class java.util.LinkedList<AnyType>
    list.add(list.size(), t);
    ^
    DoubleEndedPriorityQueue.java:49: cannot find symbol
    symbol : method sort(java.util.LinkedList<AnyType>)
    location: class java.util.Collections
    Collections.sort(list);
    ^
    Note: DoubleEndedPriorityQueue.java uses unchecked or unsafe operations.




    import java.util.Collections;
    import java.util.Comparator;
    import java.util.LinkedList;

    public class DoubleEndedPriorityQueue<AnyType> {

    private LinkedList<AnyType> list;

    public DoubleEndedPriorityQueue()
    {
    // initialize the list
    list = new LinkedList<AnyType>();
    }

    public <AnyType extends Comparable<? super AnyType>> AnyType
    findMin()
    {
    // find the minimum item in the queue and return it

    return (AnyType) list.getFirst();
    }

    public <AnyType extends Comparable<? super AnyType>> AnyType
    findMax()
    {
    // find the maximum item in the queue and return it
    return (AnyType) list.getLast();
    }

    public <AnyType extends Comparable<? super AnyType>> AnyType
    deleteMin()
    {
    // find and remove the minimum item in the queue, and return it
    return (AnyType) list.pollFirst();
    }

    public <AnyType extends Comparable<? super AnyType>> AnyType
    deleteMax()
    {
    // find and remove the maximum item in the queue, and return it
    return (AnyType) list.pollLast();
    }


    public <AnyType extends Comparable<? super AnyType>> void
    add(AnyType t)
    {
    list.add(list.size(), t);
    Collections.sort(list);
    }
    }

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,863
    Rep Power
    19

    Default

    Not too sure about the first one, but the sort is because AnyType is not a match for "extends Comparable". Since your LinkedList does not require its contents to implement Comparable, the call to sort() fails to compile.

  3. #3
    wesgarner is offline Member
    Join Date
    Sep 2009
    Posts
    2
    Rep Power
    0

    Default

    Yeah, I believe the class was supposed to be generic, but I switched the LinkedList variable type to the one I needed and called it a day

Similar Threads

  1. LinkedList help
    By jigglywiggly in forum New To Java
    Replies: 6
    Last Post: 09-19-2009, 07:24 AM
  2. LinkedList problem
    By Mika in forum New To Java
    Replies: 7
    Last Post: 02-18-2009, 02:10 PM
  3. Replies: 4
    Last Post: 02-13-2009, 07:42 AM
  4. LinkedList-java
    By kamali in forum New To Java
    Replies: 2
    Last Post: 09-26-2008, 03:29 PM
  5. how to use LinkedList
    By fred in forum Advanced Java
    Replies: 1
    Last Post: 07-24-2007, 01:52 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •