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 4 of 4

Thread: Homework help

  1. #1
    Junior Member
    Join Date
    Sep 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Homework help

    I have a homework assignment in which I am basically supposed to gather a set of data, and store them in three separate data structures at the same time while being able to perform several actions on each data set simultaneously. The three data structures are: sorted linked list - no sentinels, doubly-linked sorted list with sentinel nodes, and an unsorted array. When the program is executed, an insert, delete, member (Pointing to a pointer), and quit method must be executed on each data set. I have written a singly linked list class as we are not allowed to utilize the API, but I am still unsure how to implement a sort routine on the class, and also how to set up the member method. What I am looking for is some general help in how to set up the main class of this program, as well as help on writing the doubly - linked list and the array classes. Any and all help is appreciated as I am kind of desperate at this point, and forgive me if this is in the wrong section and I'd ask that a moderator please move this to the correct category.

    Thanks in advance


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Homework help

    It helps the people who answer questions if you always post the related code with the question.




    but I am still unsure how to implement a sort routine on the class
    Were you given a specific sort to use or are you to choose the best option for the task? What sort would work best on the given data set?




    general help in how to set up the main class of this program...as well as help on writing the doubly - linked list and the array classes
    What do you have for the main class so far? What do the requirements of the class include (that you have questions on)?




    and forgive me if this is in the wrong section
    Looks like a good place mate

  3. #3
    Junior Member
    Join Date
    Sep 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Homework help

    Quote Originally Posted by jps View Post
    It helps the people who answer questions if you always post the related code with the question.




    Were you given a specific sort to use or are you to choose the best option for the task? What sort would work best on the given data set?




    What do you have for the main class so far? What do the requirements of the class include (that you have questions on)?




    Looks like a good place mate
    First of all thanks for the reply, Here is the code for the link class as well as for the linked list class which includes a main tester class. The values are hardcoded for now but will eventually have to be read in. I do not have to use any type of specific sort routine, so whatever the simplest way to sort the results will suffice.

    public class Link{
     
      public String data1,data2;
      public double income;
      public Link next;
     
     
      public Link(String d1, String d2, double d3){
        data1 = d1;
        data2 = d2;
        income = d3;
      }
          public void printListElements (){
          System.out.println(" Elements are " + data1+data2+income);
     
          }
      }

    public class LinkedList{
      private Link first;
      public LinkedList(){
        first = null;
      }
     
      public boolean isEmpty(){
        return first==null;
      }
     
      public void insert(String s1, String s2, double d1){
        Link linklist = new Link(s1, s2, d1 );
        linklist.next=first;
        first=linklist;
      }
     
      public Object delete(){
        Link temp=first;
        first=first.next;
        return temp;
      }
     
      public void printList(){
        Link current=first;
        System.out.println("List Elements are ");
        while (current !=null){
          current.printListElements();
          current=current.next;
        }
      }
     
      public static void main (String args []){
        LinkedList linkedList1=new LinkedList();
        linkedList1.insert("Bob","Jim",3.0);
        linkedList1.insert("Rick","Terry", 1500.00);
        linkedList1.insert("James","Henry", 2000.00);
        linkedList1.insert("Harold","Anthony", 3000.00);
     
        linkedList1.printList();
     
        linkedList1.delete();
     
        linkedList1.printList();
      }
      }

    The best I can figure, I will have to write overloaded methods for the insert, delete, and member classes for each of the data structures so that when the class is executed it will be applied on all three data structures. Below is a copy of the rubric for this assignment if that helps.
    The purpose of this assignment is to give you a little experience programming with pointers. You are allowed to use resources on the internet to try to do this assignment (pseudo-code shouldn’t be hard to find).

    You will have a set of data (integers) and will implement three operations on this set:
    • insert(e): insert element e into the set
    • delete(e): delete element e from the set
    • member(e): return a pointer to the node whose value field is e (otherwise return null)
    • print( ): print the elements of the set

    You will represent the set using the following data structures:
    • sorted linked list - no sentinels.
    • doubly-linked sorted list with sentinel nodes
    • unsorted array
    o member will return the index that elem is stored in (or -1 if it is not in the set)

    Your program will behave as follows:
    Please enter a command:
    insert e
    delete e
    member e
    quit
    if user entered insert e: print the data structure after the insert is executed
    if user entered delete e: print the data structure after the delete is executed
    print an error message if e is not in the set
    if user entered member e: print yes/no.
    if user entered quit: the program terminates
    Please enter a command: …

    Note that every time the user enters a command you will execute that command on all three data structures (with the obvious exception of the quit command).

  4. #4
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Homework help

    I don't see a question to answer. If I was you I would not try to write a program that does everything. Break the problem down into smaller concepts first and work up to the final project. You are supposed to save data in three different data structures, you could worry about just one structure at a time. You are supposed to have four methods for each structure. You could start with zero and add those methods in when other things are compiled, tested, and functional.

Similar Threads

  1. I am doing my homework =D
    By valenciajv in forum Java Theory & Questions
    Replies: 9
    Last Post: October 7th, 2011, 04:39 PM
  2. Homework
    By jdonaldson in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 9th, 2011, 11:09 AM
  3. Homework help
    By cd247 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 11th, 2009, 05:56 PM
  4. need help with homework!
    By programmer12345 in forum Java Theory & Questions
    Replies: 2
    Last Post: September 27th, 2009, 05:34 AM
  5. [SOLVED] What is cast operator and how to use it?
    By napenthia in forum Java Theory & Questions
    Replies: 11
    Last Post: April 27th, 2009, 06:11 AM