A Walk in the Woods

Would you like to react to this message? Create an account in a few clicks or log in to continue.

A website where friends talk about their favourite games, the next best drinks, programming projects and whatever else is cool at the time!


2 posters

    Ben's Java Assignment 1

    DarkShadow14
    DarkShadow14
    Owner


    Posts : 81
    Join date : 2011-09-02
    Age : 33
    Location : Canada

    Ben's Java Assignment 1 Empty Ben's Java Assignment 1

    Post by DarkShadow14 Wed Oct 05, 2011 6:03 pm

    1. Read the first 50 lines of input and then write them out in reverse order. Read the next 50 lines and then write them out in reverse order. Do this until there are no more lines left to read.
    In other words, your output will start with the 50th line, then the 49th, then the 48th, and so on down to the first line. This will be followed by the 100th line, followed by the 99th, and so on down to the 51st line. And so on.

    Your code should never have to store more than 50 lines at any given time.
    Part1.java:
    2. Read the whole input one line at a time. Then output all lines sorted by length, with the shortest lines first. In the case where two lines have the same length, resolve their order using the usual sorted order.
    Part2.java:
    3. Read the entire input one line at a time and then output the even numbered lines (starting with the first line, line 0) followed by the odd-numbered lines.
    Part3.java:
    4. Read the input one line at a time and write each line to the output only if you have already read this line before. (The end result is that you remove the first occurrence of each line.)
    Take special care so that a file with a lot of duplicate lines does not use more memory than what is required for the number of unique lines.
    part4.java:
    5. Read the input one line at a time. At any point after reading the first 42 lines, if some line is blank (i.e., a string of length 0) then output the line that occured 42 lines prior to that one. For example, if Line 242 is blank, then your program should output line 200. This program should be implemented so that it never stores more than 43 lines of the input at any given time.
    Part5.java:
    6. Write the generic function Part6.mongeanShuffle(List l) that simulates a perfect Mongean shuffle on the list l. More precisely, given a list that contains the number 0,1,2,3,...,n-1. The result should be a list containing
    n-1, n-3, n-5,...,0,1,3,5,...,n-2 (if n is odd) or
    n-2, n-4, n-6,...,0,1,3,5,...,n-1 (if n is even)
    Write your code so that it works efficiently (in O(n) time) even if l is a LinkedList

    Note that this operation is destructive. It does not create a new list. Instead, it modifies the order of the elements in the list l.
    Part6.java:

    EDIT: I definitely need to find a better way of posting code since this way messes up all the indentation. I might just put the files up on mediafire later.
    Blacksky
    Blacksky


    Posts : 59
    Join date : 2011-09-05
    Location : INTERNETZ

    Ben's Java Assignment 1 Empty Re: Ben's Java Assignment 1

    Post by Blacksky Thu Oct 06, 2011 3:50 pm

    holy fuck lol, im trying to follow the code and the instruction but its so confusing. Glad im not taking java yet....YYYYEEEEEEEEEEEETTTTTTTTTT No

      Similar topics

      -

      Current date/time is Thu May 16, 2024 9:30 am