Go Back   Computer Forums > General Computing > Programming
Click Here to Login
Join Computer forums Today


Reply
 
Thread Tools Search this Thread Display Modes
 
Old 11-10-2004, 04:04 PM   #1
Solid State Member
 
Join Date: Nov 2004
Posts: 6
Send a message via AIM to nburvi1
Default need some java help

well i am just lost about how to use linked lists what i need to do is this

Given a sequence of numbers, write a class named my_Special_Reverse to store them in a linked list and then print them in reverse order on the screen except the three numbers in the middle. For example, given 103 23 4 13 21 18 19 as input, your program should print out 19 18 4 13 21 23 103. The input will have an odd number of integers.

and i am just lost about how to do it?
__________________

nburvi1 is offline   Reply With Quote
Old 11-10-2004, 08:09 PM   #2
Daemon Poster
 
broknhabit's Avatar
 
Join Date: Sep 2004
Posts: 1,222
Send a message via AIM to broknhabit
Default Re: need some java help

Code:
import java.util.*;

public class my_Special_Reverse
{
	public static void main(String args[])
	{
		LinkedList list = new LinkedList();
		for(int i = 0; i < args.length; i++)
		{
			list.add(args[i]);
		}
		printList(arrangeList(list));
	}
	private static LinkedList arrangeList(LinkedList l)
	{
		LinkedList list = new LinkedList();
		for(int i = 0; i < l.size(); i++)
		{
			list.add(l.get(i));
		}
		if(list.size() > 3)
		{
			int length = list.size();
			int x = ((length - 3) / 2);
			LinkedList list2 = new LinkedList();
			LinkedList list3 = new LinkedList();
			for(int i = (x - 1); i >= 0; i--)
			{
				list2.add(list.get(i));
			}
			for(int i = (length - x); i < length; i++)
			{
				list2.add(list.get(i));
			}
			for(int i = (list2.size() - 1); i >= 0; i--)
			{
				list3.add(list2.get(i));
			}
			for(int i = 0; i < x; i++)
			{
				list.set(i, list3.get(i));
			}
			int y = x;
			for(int i = (length - 1); i >= (length - x); i-- )
			{
				list.set(i, list3.get(y));
				y++;
			}
		}
		return list;
	}
	private static void printList(LinkedList l)
	{
		String text = "";
		for(int i = 0; i < l.size(); i++)
		{
			text += l.get(i) + " ";
		}
		System.out.println(text);
	}
}
This can be run from the command prompt, using the numbers you want to sort as arguments.
__________________

__________________
seriously
broknhabit is offline   Reply With Quote
Old 11-10-2004, 09:48 PM   #3
Solid State Member
 
Join Date: Nov 2004
Posts: 6
Send a message via AIM to nburvi1
Default Re: need some java help

where did u find that? or did u write it urself?
nburvi1 is offline   Reply With Quote
Old 11-10-2004, 10:26 PM   #4
Daemon Poster
 
broknhabit's Avatar
 
Join Date: Sep 2004
Posts: 1,222
Send a message via AIM to broknhabit
Default Re: need some java help

i wrote it myself
__________________
seriously
broknhabit is offline   Reply With Quote
Old 11-11-2004, 02:01 AM   #5
Solid State Member
 
Join Date: Nov 2004
Posts: 6
Send a message via AIM to nburvi1
Default Re: need some java help

nice, thank you again for your help, my code was fairly similar the syntax was just off.
nburvi1 is offline   Reply With Quote
Old 11-11-2004, 04:11 PM   #6
Daemon Poster
 
broknhabit's Avatar
 
Join Date: Sep 2004
Posts: 1,222
Send a message via AIM to broknhabit
Default Re: need some java help

alright, glad to be of service
__________________
seriously
broknhabit is offline   Reply With Quote
Old 11-11-2004, 09:48 PM   #7
Golden Master
 
athlon64fx's Avatar
 
Join Date: Aug 2004
Posts: 6,153
Send a message via MSN to athlon64fx
Default Re: need some java help

he he javascript is cool isnt it!?
athlon64fx is offline   Reply With Quote
Old 11-11-2004, 09:59 PM   #8
Daemon Poster
 
broknhabit's Avatar
 
Join Date: Sep 2004
Posts: 1,222
Send a message via AIM to broknhabit
Default Re: need some java help

lol 'tis real java, not javascript
__________________
seriously
broknhabit is offline   Reply With Quote
Old 11-11-2004, 10:06 PM   #9
Solid State Member
 
Join Date: Nov 2004
Posts: 6
Send a message via AIM to nburvi1
Default Re: need some java help

ha
nburvi1 is offline   Reply With Quote
Old 11-11-2004, 10:20 PM   #10
Golden Master
 
athlon64fx's Avatar
 
Join Date: Aug 2004
Posts: 6,153
Send a message via MSN to athlon64fx
Default Re: need some java help

heheheh!!!
__________________

athlon64fx is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



All times are GMT -5. The time now is 09:19 AM.


Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0