#How to Reverse order of linked list

1 messages · Page 1 of 1 (latest)

gloomy lintel
#

Couldn't you create a second linked list and remove the last node from the first list and add it to the new list and do that until the first list is empty?

mint abyss
#

Have you tried using recursion to print it in reverse order?

mint abyss
#

What were you doing to cause the error entering an empty line?

#

Isn't an empty string 0 length like ""

#

I don't remember in java tbh but give it a try

#

Np

#

If "". length () is 0 and considered empty non empty would have a greater value or a positive length

#

Yes

#

The user can input an empty line though

#

I don't remember how that function evaluates is it like a<b<aa<ab?

#

Looks like if they have the same length and same characters it returns 0 if they have same length and different characters it returns the difference in character values so a-b =-1 and a positive 1 if its b-a

#

The compare function

#

Instead of checking the lengths you should be using the compare to functions

#

Can you go to voice chat?

#

Ah yeah go and you can just type any questions in here I'm in my bed typing on my phone

#

I'm in there now in general

visual frigate
#

^Z it should print the values

#

kk

#

ok

#

thats the result

#

yeah

#

everything below ^Z

#

is the output

#

i dont think so

#

Read the input one line at a time and output the current line if and only if it is strictly larger than all other lines read so far or strictly smaller than the previously outputted line. If this is the first nonempty line you read, it is considered larger than anything you've read so far.

#

well pizza should be the largest right?

#

oh wait

#

nonempty line you read, it is considered larger than anything you've read so far.

#

this doesnt include the sdas thing right?

#

so pizza is the largest only to start right?

#

ok

#

shouldnt hat, caasasa, dss and sdas be in the output?

#

ill test it again with some new words

#

this is the entire question

#

"Read the input one line at a time and output the current line if and only if it is strictly
larger than all other lines read so far or strictly smaller than the previously outputted line. If this
is the first nonempty line you read, it is considered larger than anything you've read so far."

#

hmm

#

oh yeah

#

ur right

#

the only time it wouldnt show is when they are equal

#

so everything else should be printed

#

how would I check if its equal to 0?

#

.equals?

#

kk

#

didnt output anything this time

#

oh

#

!=

#

this is what happened

#

kk

#

I can check rq

#

why not?

#

so I should delete the else if?

#

what about line = smallest;?

#

ok

#

I have an online checker

#

its telling me the output is incorrect

#

Output is incorrect.
Line 7, correct != result ['g'!='2']
Execution time: 0.10 seconds.

#

i think i might have test cases let me double check

#

this is the input

#

1
3
8
4
5
6
7
9
2

#

this is output

#

1
3
8
4
9
2

#

ill brb in a min rq

#

sorry about that

#

kk

#

ok

#

1 sec

#

ok so what do i have to do?

#

done

#

boolean extraline = true;

#

like before the if after the for?

#

like this?

#

like this?

#

kk

#

done

#

like this?

#

ok

#

where does it go?

#

kk

#

open brackets where?

#

oh okay

#

oh yeah

#

im like out of it rn lol

#

sorry

#

i added them

#

kk

#

yeah

#

thats what it tells me

#

we have like an online submission server

#

it has its own stuff to test that we cant see

#

it runs the code and tells us if we did it right or wrong

#

thats the only example

#

hmm

#

let me think

#

this is what someone else said

#

I have noticed some weird things when I use different inputs like 100... apparently 2 > 100 lexicographically. Is that valid on gradescope? would duplicate lines (i.e. using 100 twice as input) affect it in any way on gradescope?

#

cause there code was working with the test case

#

but also failed the second test

#

not really sure what that means tho

#

thats what someone said was the problem with theres

#

it passed the first test case but failed wheres mine did

#

wdym?

#

so line.length >= check.length &&

#

oh so on the else if line

#

this goes in front

#

i have compareTo in two plaves

#

oh okay 1 min

#

so it looks like this?

#

ok let me run it rq

#

what inputs should i type

#

i might have put in the wrong ones in

#

those 4?

#

yeah

#

ok

#

done

#

i ran the test too

#

yeah

#

its cut off

#

kk

#

hold up

#

gotta complie code

mint abyss
#

1 2 100 101 99 101 100 102

visual frigate
#

thats what came out

#

oh

#

what happened?

#

okay

#

any idea?

mint abyss
#

can u still hear me?

visual frigate
#

now i can

#

like this?

#

ok

#

like this?

#

kk

#

this is fine?

#

kk

#

ok

mint abyss
#

If((line.length>check.length) or (line.length==check.length&&line.compareto(check)>0)

visual frigate
#

like this?

#

kk

#

yeah idek why

#

ill check

#

would duplicate lines (i.e. using 100 twice as input) affect it in any way on gradescope?

would duplicate lines (i.e. using 100 twice as input) affect it in any way on gradescope?

gradescope wouldn't be affected, your code would

okay that might be one of my issues then

#

thats the last thing the person said

#

ok

#

seems like there is an issue

#

100 printed twice no?

#

oh ok

#

yeah

#

i just dont understand why it doesnt work lol

#

1 sec

#

i dont unfortunately

#

when someone asked about more test cases to test output

#

this was some FAQ

#

it looks fine to me

#

something is going wrong in this

#

45

#

hi

#

so like this?

#

ok

#

wait what?

#

didnt print the 7 this time

#

😭

#

i dont think they ever stated it

#

i think its trying to test a string number

#

like this

#

'293230232'

#

idk if that changes anything

#

is this fine?

#

yeah

#

uhh

#
String largeLine = null, currentLine;
// loop to read the lines from the reader r till an empty line is read or null line is read
do
{
// read a line
currentLine = r.readLine();

// end of reading has not been reached
if(currentLine != null ) {

// if this is the first line read or current line is larger than the any other line read so far
// since first line will be a larger line as no other line has been read so far
if((largeLine == null) || currentLine.compareTo(largeLine) > 0)
{
// set currentLine as largerLine and output it to writer w
largeLine = currentLine;
w.println(largeLine);
}
}
}while(currentLine != null && currentLine.length() > 0);

}
#

this is a solution i think

#

wait i have to add what?

#

so like this?

mint abyss
#

1 2 3 2 1 es 4 5

visual frigate
#

when i hit space it just enters the code

#

if i hit enter it also outputs the code

#

like it will stop taking input and output what was in it

#

it failed on the first step this time

#

i assume so

#

cause it stops taking input after hitting enter twice

#

while leaving a space

#

so the input can be both strings and numbers

#

Ok

#

wdym?

#

i dont

#

its just provided to us

mint abyss
#

Okay

#

Lol did you tell him what you tried and ask if the general idea is correct?

#

Try some more tests then see if you can find something incorrect then

#

Did you ask if empty string should end the input part of the program and start printing the order?

#

How is input closed

#

Oh

#

Maybe you can try removing line!=null from the for loop then see if it fixes it

#

Just leaving it blank

#

Looks right but u would have to check on the site

#

Yes

#

Didn't you write spaces multiple times though so the duplicate spaces were removed

#

But you can just add a check that the input isn't a space if spaces are not allowed

mint abyss
#

You removed the extra line equals true so it only prints the first number less than the max

#

Also the extra line only works on the first iteration

#

The way that you had it before I meant

mint abyss
#

I need to see the code

#

You need to move the extra line check cause it uses the extra line regardless of the comparison in the last version

#

But you want to save it for times when the number isn't already bigger than the last

#

It's like doing an if extra line then else if the compare is positive then else if the compare is negative

#

But you want to check if it's positive then else if it's negative and you have an extealine available

#

Move it back to how it was last night lol

#

Move it below the check for if the compare is positive

#

Like under the entire block of logic inside of that if

#

The current line and previous makes sense

#

I would have to look at it later I'm pretty tired atm

mint abyss
#

Hey did you have any luck with it?