Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: I need some help... Please !

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default I need some help... Please !

    HI,

    I have this assignment for school and I really need help on this one. I am supposed to write a program with a menu that gives me the possibility to choose what to do. The program will end by choice in menu.The list will not be sorted and numbers may show up several times in the list. I am not able to use array list These functions must be implemented in the program:

    1. Delete an element at the beginning at a list
    2. Add an element at the end of the list
    3. Delete an element at the end of the list
    4. Delete an element with known value (only the first)
    5. Add an element after a element with known value (only the first)
    6. Add an element before a element with known value (only the first)
    7. print the length of the list
    8. count the number of times a known number appears in the list. print the number of times
    9. Print the whole list, maximum 5 elements pr. line
    10. Delete the whole list. Number of elements deleted will be printed.

    This is how far i got on the whole thing. It is 7-10 i need help with:

    package oblig1;

    class Node {
    int element;
    Node next;
    public Node(int e, Node n) {
    element = e;
    next = n;
    }
    public int findElement() {
    return element;
    }
    public Node findNext() {
    return next;
    }
    }

    package oblig1;

    import oblig1.Node;

    class SingleLink {
    private Node head = null;
    private int size = 0;
    public int findNumberOf() {return size;}
    public Node findhead() {return head;}
    public void insertFront(int verdi) {
    head = new Node(verdi, head);
    ++size;
    }
    public void insertBack(int verdi) {
    if (head != null) {
    Node this = head;
    while (this.next != null) this = this.next;
    this.next = new Node(verdi, null);
    }
    else head = new Node(verdi, null);
    ++size;
    }
    public Node remove(Node n) {
    Node previous = null;
    Node this = head;
    while ( this != null && this != n) {
    previous = this;
    this = this.next;
    }
    // Now this points at the searched for and previous to the one in front
    if (this != null) {
    if (previous != null) previous.next = this.next;
    else head = this.next;
    this.next = null;
    --size;
    return this;
    }
    else return null;//Doesnt exist
    }
    public void DeleteNodeWithValue(value)
    {
    Node cp, pp;
    cp = hode;
    pp = null;

    if(pp == null)
    {
    hode = cp.next
    }
    while(cp != null && cp. element != value)
    {
    pp = cp;
    cp = cp.next
    }
    if (cp == null)
    return;
    pp.next = cp.next
    else
    {
    size--;
    }

    public Node findNum(int Num) {
    Node this = head;
    if (Num < size) {
    for (int i = 0; i < Num; ++i) this = this.next;
    return this;
    }
    else return null;
    }
    public void delAll() {
    head = null;
    size = 0;
    }
    }

  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: I need some help... Please !

    Some words to the wise- use a more descriptive title. We know you need help, so it's best to give people a clue as to what you need help with. Otherwise people will just skip over your thread. Also, please use the highlight tags when formatting code, otherwise it's pretty impossible to read.

    Where exactly are you stuck for 7-10? What are you confused about? What have you tried for them? I suggest you take these problems one at a time. Write a method that does just one problem, and make an SSCCE out of that method. That way it's easier to test and easier for us to help you.

    Best of luck.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Feb 2012
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: I need some help... Please !

    Thank you for your comments. I will do so next time. some of my problems has been figured out with a little help.

Tags for this Thread