Tuesday 7 May 2013

Linked Lists - Java | Dream.In.Code


Example
#{example}
"); ipb.editor_values.get('templates')['togglesource'] = new Template("
??? Cancel Source Edit
"); ipb.editor_values.get('templates')['toolbar'] = new Template(""); ipb.editor_values.get('templates')['button'] = new Template("
  • Icon
  • "); ipb.editor_values.get('templates')['menu_item'] = new Template("
  • #{title}
  • "); ipb.editor_values.get('templates')['togglesource'] = new Template("
    ??? Cancel Source Edit
    "); ipb.editor_values.get('templates')['emoticons_showall'] = new Template(""); ipb.editor_values.get('templates')['emoticon_wrapper'] = new Template("

    Emoticons

    "); // Add smilies into the mix ipb.editor_values.set( 'show_emoticon_link', false ); ipb.editor_values.set( 'bbcodes', $H({"snapback":{"id":"1","title":"Post Snap Back","desc":"This tag displays a little linked image which links back to a post - used when quoting posts from the board. Opens in same window by default.","tag":"snapback","useoption":"0","example":"[snapback]100[/snapback]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"0","image":""},"topic":{"id":"5","title":"Topic Link","desc":"This tag provides an easy way to link to a topic","tag":"topic","useoption":"1","example":"[topic=1]Click me![/topic]","switch_option":"0","menu_option_text":"Enter the topic ID","menu_content_text":"Enter the title for this link","single_tag":"0","optional_option":"0","image":""},"post":{"id":"6","title":"Post Link","desc":"This tag provides an easy way to link to a post.","tag":"post","useoption":"1","example":"[post=1]Click me![/post]","switch_option":"0","menu_option_text":"Enter the Post ID","menu_content_text":"Enter the title for this link","single_tag":"0","optional_option":"0","image":""},"spoiler":{"id":"7","title":"Spoiler","desc":"Spoiler tag","tag":"spoiler","useoption":"0","example":"[spoiler]Some hidden text[/spoiler]","switch_option":"0","menu_option_text":"","menu_content_text":"Enter the text to be masked","single_tag":"0","optional_option":"0","image":""},"acronym":{"id":"8","title":"Acronym","desc":"Allows you to make an acronym that will display a description when moused over","tag":"acronym","useoption":"1","example":"[acronym='Laugh Out Loud']lol[/acronym]","switch_option":"0","menu_option_text":"Enter the description for this acronym (EG: Laugh Out Loud)","menu_content_text":"Enter the acronym (EG: lol)","single_tag":"0","optional_option":"0","image":""},"hr":{"id":"12","title":"Horizontal Rule","desc":"Adds a horizontal rule to separate text","tag":"hr","useoption":"0","example":"[hr]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"1","optional_option":"0","image":""},"php":{"id":"14","title":"PHP Code","desc":"Allows you to enter PHP code into a formatted/highlighted syntax box","tag":"php","useoption":"0","example":"[php]$variable = true;\n\nprint_r($variable);[/php]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"0","image":""},"html":{"id":"15","title":"HTML Code","desc":"Allows you to enter formatted/syntax-highlighted HTML code","tag":"html","useoption":"0","example":"[html]\n \n[/html]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"0","image":""},"sql":{"id":"16","title":"SQL Code","desc":"Allows you to enter formatted/syntax-highlighted SQL code","tag":"sql","useoption":"0","example":"[sql]SELECT p.*, t.* FROM posts p LEFT JOIN topics t ON t.tid=p.topic_id WHERE t.tid=7[/sql]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"0","image":""},"xml":{"id":"17","title":"XML Code","desc":"Allows you to enter formatted/syntax-highlighted XML code","tag":"xml","useoption":"0","example":"[xml]\n \n Test\n \n[/xml]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"0","image":""},"member":{"id":"31","title":"Member","desc":"Given a member name, a link is automatically generated to the member's profile","tag":"member","useoption":"1","example":"[member=skyhawk133] runs this site.","switch_option":"0","menu_option_text":"Input Username of Member","menu_content_text":"","single_tag":"1","optional_option":"0","image":"memberbbcode.png"},"extract":{"id":"33","title":"Extract Blog Entry","desc":"This will allow users to define an extract for an entry. Only this piece of the entry will be displayed on the main blog page and will show up in the RSS feed.","tag":"extract","useoption":"0","example":"[extract]This is an example![/extract]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"0","image":""},"blog":{"id":"34","title":"Blog Link","desc":"This tag provides an easy way to link to a blog.","tag":"blog","useoption":"1","example":"[blog=100]Click me![/blog]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"0","image":""},"entry":{"id":"35","title":"Blog Entry Link","desc":"This tag provides an easy way to link to a blog entry.","tag":"entry","useoption":"1","example":"[entry=100]Click me![/entry]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"0","image":""},"twitter":{"id":"36","title":"Twitter","desc":"A tag to link to a user's twitter account","tag":"twitter","useoption":"0","example":"[twitter]userName[/twitter]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"0","image":"twitter.png"},"inline":{"id":"37","title":"Inline Code","desc":"Formats code inline instead of in a seperate code box. ","tag":"inline","useoption":"0","example":"[inline]style=\"font-size: 12px;\"[/inline]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"0","image":""},"il":{"id":"38","title":"Abbreviated Inline (IL)","desc":"Abbreviated version of the [inline] tag. ","tag":"il","useoption":"0","example":"[il]Code Here[/il]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"0","image":"il2.png"},"code":{"id":"41","title":"Code","desc":"Allows you to enter general code","tag":"code","useoption":"1","example":"[code]$text = 'Some long code here';[/code]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"1","image":""}}) ); ipb.vars['emoticon_url'] = "http://cdn.dreamincode.net/forums/public/style_emoticons/default"; //Search Setup ipb.vars['search_type'] = 'forum'; ipb.vars['search_type_id'] = 32; ipb.vars['search_type_2'] = 'topic'; ipb.vars['search_type_id_2'] = 320408; //]]>

    2 Replies - 56 Views - Last Post: Yesterday, 11:18 AM Rate Topic: -----

    #1 Jars ?Icon User is offline

    Reputation: 0

    • Posts: 16
    • Joined: 12-February 13

    Posted Yesterday, 08:39 AM

    Hey guys i have come to the forum again for some help and direction. I have an assignment that i need to read in 3 .txt files and remove the middle value for each file and then print the results.

    Create a linked list to hold the items from the first fi le (input1.txt);
    2. Print the linked list;
    3. Remove the rst, middle and last items from the linked list;
    4. Print the linked list after three items removed;
    5. Create a linked list to hold the items from the second file (input2.txt);
    6. Print the linked list;
    7. Remove the rst, middle and last items from the linked list;
    8. Print the linked list after three items removed;
    9. Create a linked list to hold the items from the third file (input3.txt);
    10. Print the linked list;
    11. Remove the first, middle and last items from the linked list;
    12. Print the linked list after three items removed;

    Now we are told to use 3 methods with this program.
    1. public static LinkedList<String> readItems(String fileName);
    2. public static void removeFirstMiddleLast(LinkedList<String> l);
    3. public static void printListWithSeparator(LinkedList<String> l);

    As i make my programs i like to get the basic setup done first before i get into depth with everything else. So what i have done is basically create the whole program under my whole main method. Which so far is working, but i am having issues turning it back into the 3 methods that i need. Seeing how the first method is only using one file at a time. I am assuming i need to use a loop of some sort. Also i have no finished the "1 main method" because i figured i would start moving towards the direction of the 3 methods.

    
import java.io.*; import java.util.*;  public class Test { 	public static void main(String [] arg) throws FileNotFoundException 	{ 		int count1 = 0; 		int count2 = 0; 		int count3 = 0; 		 		LinkedList<String> list1 = new LinkedList<String>(); 		LinkedList<String> list2 = new LinkedList<String>(); 		LinkedList<String> list3 = new LinkedList<String>(); 		 		 		//File Reader 		File file1 = new File("E:\\Programming 2\\eclipse\\Assignment 6\\input1.txt"); 		Scanner f1 = new Scanner(file1); 		String f1Contents; 		while(f1.hasNext()) 		{ 			count1++; 			f1Contents = f1.next(); 			list1.add(f1Contents); 		} 		 		File file2 = new File("E:\\Programming 2\\eclipse\\Assignment 6\\input2.txt"); 		Scanner f2 = new Scanner(file2); 		String f2Contents; 		while(f2.hasNext()) 		{ 			count2++; 			f2Contents = f2.next(); 			list2.add(f2Contents); 		} 		 		File file3 = new File("E:\\Programming 2\\eclipse\\Assignment 6\\input3.txt"); 		Scanner f3 = new Scanner(file3); 		String f3Contents; 		while(f3.hasNext()) 		{ 			count3++; 			f3Contents = f3.next(); 			list3.add(f3Contents); 		} 		f1.close(); 		f2.close(); 		f3.close(); 		 		//Link List Creation 		ListIterator<String> iterator1 = list1.listIterator(); 		while(iterator1.hasNext()) 		{ 			String l1 = iterator1.next(); 			System.out.print(l1+" "); 		} 		System.out.println(""); 		ListIterator<String> iterator2 = list2.listIterator(); 		while(iterator2.hasNext()) 		{ 			String l2 = iterator2.next(); 			System.out.print(l2+" "); 		} 		System.out.println(""); 		ListIterator<String> iterator3 = list3.listIterator(); 		while(iterator3.hasNext()) 		{ 			String l3 = iterator3.next(); 			System.out.print(l3+" "); 		} 	} } 

    I also have attached the output file/input1/input2/input3. So you all can see what the files are that i am dealing with and what the output needs to look like.

    Thanks all in advance,
    Jars



    Is This A Good Question/Topic? 0

    Replies To: Linked Lists

    #2 jon.kiparsky ?Icon User is offline

    Reputation: 5353

    • Posts: 8,569
    • Joined: 19-March 11

    Re: Linked Lists

    Posted Yesterday, 09:18 AM

    So you've established the proof of concept and now you want to make it clean? Probably easiest to start from scratch, honestly, and do it right from the start this time. You have three methods required. Start by writing stubs for each of those. Here, I'll give you those:
    
  public static LinkedList<String> readItems(String fileName) {       LinkedList<String> list = new LinkedList<String>();       list.add("foo");       list.add("bar");       list.add("baz");       return list; }   public static void removeFirstMiddleLast(LinkedList<String> l) {     return; }  public static void printListWithSeparator(LinkedList<String> l) {     return; } 

    Then, make the methods work. You can use your main method to test them, if you want, or you can write test methods for them and call them from main.

    Finally, write code in main that calls these methods to meet the assignment requirements.


    #3 Jars ?Icon User is offline

    Reputation: 0

    • Posts: 16
    • Joined: 12-February 13

    Re: Linked Lists

    Posted Yesterday, 11:18 AM

    how does on pass a list between methods?
    Figured it out

    This post has been edited by Jars: Yesterday, 11:30 AM


    Page 1 of 1


    Source: http://www.dreamincode.net/forums/topic/320408-linked-lists/

    12 12 12 Anne Hathaway Wardrobe Malfunction Adrienne Maloof Telemundo real housewives of beverly hills Pink Floyd 12 12 12 Concert

    No comments:

    Post a Comment