How to print the contents of doubly-Linked List

Hi
I have a DLList consists of header , trailer and 10 linked nodes in between
Is there a simple way to print the contents ie "the elements"
of the list
thanks

In general you should write an iterator for every linked data structure for fast traversal. I'm guessing you're writing your own DLL for an assignment because one normally uses the LinkedList structure that is included in the api. Anyway, here is an example of how the iterator is implemented for a double linked list:
http://www.theparticle.com/_javadata2.html#Doubly_Linked_Lists_with_Enumeration

Similar Messages

  • How to print the content of LinkedList int[] and LinkedList LinkedList ?

    Hi guys, its been a long time since i posted here, and now im coming back to programming using java. My problem is, how can i print the content of the list?
    Example:
    LinkedList<int[]> list = new LinkedList<int[]>;
    int[] input = {1,2,3,4,5};
    int[] input2 = {2,32,43,54,65};
    list.add(input);
    list.add(input2);
    how can i print all the content of the linkedlist?
    Please help me..I know its a dumb question but i really dunno how.
    here is the code:
    import java.util.LinkedList;
    import java.util.Scanner;
    import java.util.Arrays;
    public class Test{
         static void printThis(String[] in){
              System.out.print("Value: ");
              for(int i = 0;i<in.length;i++){
                   System.out.print(in[i] + " ");
              System.out.println();
         static void reset(String[] val){
              for(int i = 0;i<val.length;i++){
                   val[i] = "";
         public static void main(String[] args){
              LinkedList<String[]> list = new LinkedList<String[]>();
              LinkedList<String> listTrans = new LinkedList<String>();
              System.out.print("Enter the number of records: ");
              Scanner s = new Scanner(System.in);
              int numOfRecords = s.nextInt();
              System.out.print("Enter the number of records per run: ");
              s = new Scanner(System.in);
              System.out.println();
              int numOfRecordsInMemory = s.nextInt();
              String[] getData = new String[numOfRecords];
              String[] transferData = new String[numOfRecordsInMemory];
              int numOfRuns = 0;
              int counter = 0;
              for(int i = 0;i<numOfRecords;i++){
                   counter++;
                   System.out.print("Enter value number " + counter + ": ");
                   Scanner scan = new Scanner(System.in);
                   getData[i] = scan.next();
                   listTrans.add(getData);
              if(getData.length%numOfRecordsInMemory == 0){
                   numOfRuns = getData.length/numOfRecordsInMemory;
              }else if(getData.length%numOfRecordsInMemory != 0){
                   numOfRuns =(int)(getData.length/numOfRecordsInMemory)+ 1;
              System.out.println();
              System.out.println("Number of Runs: " + numOfRuns);
         int pass = 0;
         System.out.println("Size of the main list: " + listTrans.size());
         while(listTrans.size() != 0){
              if(listTrans.size() >= numOfRecordsInMemory){
                   for(int i = 0;i<numOfRecordsInMemory;i++){
                        transferData[i] = listTrans.remove();
                   System.out.println("Size of the list: " + listTrans.size());
                   printThis(transferData);
                   System.out.println();
                   Arrays.sort(transferData);
                   list.add(transferData);
                   reset(transferData);
              }else if(listTrans.size() < numOfRecordsInMemory){
                   pass = listTrans.size();
                   for(int k = 0;k<pass;k++){
                        transferData[k] = listTrans.remove();
                   System.out.println("Size of the list: " + listTrans.size());
                   printThis(transferData);
                   System.out.println();
                   Arrays.sort(transferData);
                   list.add(transferData);
                   reset(transferData);
    //This is the part that is confusing me.
    //im trying to print it but its not working.
              System.out.println("Size of the next list: " + list.size());
    //          for(int i = 0;i<list.size();i++){
    //                    System.out.println();
    //               for(int j = 0;j<list.get(i)[j].length();j++){                    
    //                    System.out.print(list.get(i)[j] + " ");

    Here's the funnest, mabye clearest way you could do it: Use 2 Mappers
    package tjacobs.util;
    import java.util.ArrayList;
    import java.util.Iterator;
    import java.util.List;
    import tjacobs.Arrays;
    public class Mapper <T>{
         public static interface MappedFunc<T> {
              void map(T value);
         public Mapper(T[] vals, MappedFunc<T> function) {
              this (new Arrays.ArrayIterator<T>(vals), function);
         public Mapper(Iterator<T> iterator, MappedFunc<T> function) {
              while (iterator.hasNext()) {
                   function.map(iterator.next());
         public static void main(String[] args) {
              String[] s = new String[] {"a","b", "c", "abc", "ab"};
              MappedFunc<String> func = new MappedFunc<String>() {
                   public void map(String s) {
                        if (s.toLowerCase().startsWith("a")) {
                             System.out.println(s);
              Mapper m = new Mapper(s, func);
    }

  • How to print the contents of a form(window)

    I'm devloping visitors application in java. After the data entry, I need to display the selected information from database along with the photo and take a printout so that it looks like a card.
    I know how to display the contents in a form. How do I print the contents of the form?
    -Thanx
    Hane

    in JComponent there is a method called print(Graphics g)
    you can use that with a Printable class
    read bout the java.print package in the java doc

  • Urgent: how to print the contents displayed in JTextPane

    hi all,
    i've a problem printing the contents typed in styled format in JTextPane, when i print the contents nothing is printed. can anyone tell how can i print the contents typed in styled format or so. the code for implementing the print is given below.
    class ContentsArea extends JTextPane implements Pritable {
       public int print(Graphics g, PageFormat pf, int pi) throws PrinterException {
          if (pi >= 1) {
             return Printable.NO_SUCH_PAGE;
          Graphics2D g2d = (Graphics2D) g;
          g2d.translate(pf.getImageableX(), pf.getImageableY());
          g2d.translate(pf.getImageableWidth() / 2,
                          pf.getImageableHeight() / 2);
          Dimension d = getSize();
          double scale = Math.min(pf.getImageableWidth() / d.width,
                                    pf.getImageableHeight() / d.height);
          if (scale < 1.0) {
              g2d.scale(scale, scale);
          g2d.translate(-d.width / 2.0, -d.height / 2.0);
          return Printable.PAGE_EXISTS;
    }i'd be grateful to all ppl who helps me.
    Afroze.

    What's the exact problem? The printer printing a blank sheet or the printer not doing anything at all? First make sure in the main program you've got something along the lines of...
    import java.awt.print.*;
    PrinterJob printerJob = PrinterJob.getPrinterJob();
    PageFormat pageFormat = printerJob.defaultPage();
    if(!printerJob.printDialog()) return; //not essential but lets the user tweak printer setup
    pageFormat = printerJob.pageDialog(pageFormat); //ditto
    printerJob.setPrintable(this, pageFormat);
    print(...);
    The above code should go in an ActionListener, triggered when the user hits a print button or menuitem. I'm guessing you already have something similar set up.
    Then your print(...) method should be similar to
    public int print(Graphics g, PageFormat pageFormat, int pageIndex)
         if(pageIndex>0) return NO_SUCH_PAGE;
         Graphics2D gg = (Graphics2D)g;
         gg.draw(whatever's going to be printed);
         return PAGE_EXISTS;
    Which it is, although yours has clever scaling stuff built in ) The only thing you're not doing is rendering the actual content.
    So if you want the contents of the textpane, it'd make sense to use something like g.drawString(myTextPane.getContents()); in the print method. Note it's g and not g2d, since Graphics2D has more complicated text handling routines.
    I'm no expert tho )

  • How to print the content of a textarea in java?

    Hello, i'm currently developping a HTML Editor in java but i've got a problem with printing job... Does anyone know a simple code to print the content of a textarea by clicking on a button?
    for instance:
    JTextarea textarea = new JTextArea();
    JButton print = new JButton ();
    file_menu.add(print) ;
    print.addActionListener(
    new ActionListener()
    public void actionPerformed(ActionEvent event)
    ////----> what could i put here to print the content of my textarea named 'textarea' ? Does anyone know a class i could implement here? for instance: 'Print print = new Print(textarea);'
    I've searched on the web but i didn't find it...
    Thanks very much for your help...
    S�bastien

    public class TA extends JTextArea implements Printable{
    public TA(){
    super();
    this.setPreferredSize(new Dimension(500,500));
    public TA(int x, int y){
    super(x,y);
    public int print(Graphics g, PageFormat pf,int pi){
    if (pi >= 1) {
    return Printable.NO_SUCH_PAGE;
    Graphics2D g2 = (Graphics2D) g;
    g2.translate(pf.getImageableX(),pf.getImageableY());
    Font f = new Font("Monospaced", Font.PLAIN,6);
    g2.setFont (f);
    g2.drawString(this.getText(),100,100);
    this.paint(g2);
    return Printable.PAGE_EXISTS;
    And use in Action Listener
    // get the print job
    if(pj.printDialog()){
    PageFormat pformat = pj.defaultPage();
    pformat.setOrientation(PageFormat.PORTRAIT);
    System.out.println(pj.defaultPage());
    pj.setPrintable(ta,pj.pageDialog(pformat));
    try{
    pj.print();
    catch(PrinterException p){

  • How to print the content of a textarea by clicking on a button?

    Hello, i'm currently developping a HTML Editor in java but i've got a problem with printing job... Does anyone know a simple code to print the content of a textarea by clicking on a button?
    for instance:
    JTextarea textarea = new JTextArea();
    JButton print = new JButton ();
    file_menu.add(print) ;
    print.addActionListener(
    new ActionListener()
    public void actionPerformed(ActionEvent event)
    ////----> what could i put here to print the content of my textarea named 'textarea' ?
    I've searched on the web but i didn't find it...
    Thanks very much for your help...
    S�bastien

    I've never tried it, but here's an article that might help:
    http://www.apl.jhu.edu/~hall/java/Swing-Tutorial/Swing-Tutorial-Printing.html

  • Really need help... How to print the 'content' of a JTextArea?

    Hello, i'm currently developping a HTML Editor in java but i've got a problem with printing job... Does anyone know a simple code to print the content of a textarea by clicking on a button?
    for instance:
    JTextarea textarea = new JTextArea();
    JButton print = new JButton ();
    file_menu.add(print) ;
    print.addActionListener(
    new ActionListener()
    public void actionPerformed(ActionEvent event)
    ////----> what could i put here to print the content of my textarea named 'textarea' ?
    I've searched on the web but i didn't find it...
    Thanks very much for your help...
    Sebastien Roupin

    thank you very much for your help... i'm checking this samples...
    Sebastien Roupin

  • How to display the contents of java.util.list in a frame???

    i should use awt only not applet...
    i need to display the contents of java.util.list in a frame...
    the contents contains rows queried from a oracle database.....
    the contents should be displayed similar to how a lable is displayed..
    please help me out..
    thanks
    dinesh

    Of course there is something in AWT:
    http://java.sun.com/j2se/1.5.0/docs/api/java/awt/List.
    htmlagain, if you carefully read the question, he needs a
    table to display a JDBC result set. There is no
    pre-made table component in AWT.Well, I read that he filled the data into a java.util.List and now wants to display this list. So a List-component should be sufficient. But I might be wrong...
    -Puce

  • How To Print the contents of a BLOB Column on a report?(Word Document)

    Requirement: The word document will be inserted in a BLOB Column and the data in the word document has to be shown on the reports or the user should be able to see the word document (atleast he should be able to view the contents)?
    The data is getting loaded in the database but not sure how to proceed further.
    Any inputs on how to proceed will be appreciated.
    Thanks.

    in JComponent there is a method called print(Graphics g)
    you can use that with a Printable class
    read bout the java.print package in the java doc

  • How to print the content in Reverse which is read from the file

    i have written a program to display the content of the file using files concept. now the task is how to display it in reverse order i.e from last to first which is read from the file.

    If it will all fit in memory read the file as you are doing now appending everything into a StringBuilder. Then use the reverse() method of that class to obtain your output.
    http://java.sun.com/javase/6/docs/api/java/lang/StringBuilder.html#reverse()

  • How to print the content of a text edit ?

    Hi to all,
    I have a view with a text edit and I want to print its content. I created a button and I want to print text edit content pressing this button. How can I do? Which java code I have to insert in that button?
    thanks a lot,
    Antonio

    Antonio,
    Sadly, there is no way to do it directly. Even in plain HTML application it is impossible to print text of UI control (<textarea> in this case).
    So you have to open new browser window containing entered text and let user print text himself. Or invoke window.print() on document load event.
    VS

  • How to print the content of a DynPro Window?

    Hello,
    Is there any DynPro (Or SAP) package that can print the current window content? If yes, can anyone please show me a code example?
    Roy

    Roy,
    Printing content of the window is almost always not a solution. Personally, I hate sites where articles are not available in printer-friendly format (either via separate page or CSS with media type printer).
    With WebDynpro it is even worse -- does end user really expect all this buttons, complex tables, combo boxes etc.?
    My advise is to either:
    1. Create Adobe PDF for user to download and print
    2. Create printer-friendly HTML and open it in external window
    3. Create MS Excel file to download.
    First and third options are well documented in SDN docs / tutorials, the second option is very easy to implement: take my code for transforming context tree to XML converting context-tree to xml? and apply necessary XSLT template. This way you may get HTML output in printer friendly form.
    Valery Silaev
    EPAM Systesm
    http://www.NetWeaverTeam.com

  • How to display the contents of an array list to a listview?

    Hi. How do I display the contents of an arraylist to a listview?
    Here is my current code:
    var c: Control= new Control();
    var simpleList: ArrayList = c.ListResult; //ListResult is an ArrayList containing strings
    var simpleListView : ListView = ListView {
            translateX: 0
            translateY: 0
            layoutX: 20
            layoutY: 80
            height: 130
            width: 200
            items: bind simpleList;
    Stage {
        title: "Trial app"
        width: 240
        height: 320
        style: StageStyle.TRANSPARENT
        scene: Scene {
            content: [ simpleListView
    } [http://img341.imageshack.us/img341/133/listview.jpg]
    My code generates the result in this screenshot above. It shows that all the contents on the arraylist is displayed in one row/item.
    It should be displayed as (see bottom image) ...
    [http://img707.imageshack.us/img707/3745/listview1.jpg]
    Do you guys have any idea on this? Thank you very much for your replies

    For your listbox data to bind the listbox requires a Sequence. This is something that you can sort out at the entrypoint of your code.
    In the example below I have used an ArrayList to simmulate the data you have entering your FX code, but then I put that list into a Sequence, in your case instead of having an ArrayList in your FX code, you simple supply the list on entry, as I have marked in the following code.
    * Main.fx
    * Created on 12-Feb-2010, 10:24:46
    package uselists;
    import javafx.stage.Stage;
    import javafx.scene.Scene;
    import javafx.scene.text.Text;
    import javafx.scene.text.Font;
    import java.util.ArrayList;
    import javafx.scene.control.ListView;
    import javafx.animation.Timeline;
    import javafx.animation.KeyFrame;
    * @author robert
    //Simmulate your data with an ArrayList
    var simpleList: ArrayList = new ArrayList;
    simpleList.add("Hello");
    simpleList.add("World");
    // *** This is what your entry point would become, just load the simpleList.toArray() into your sequence ***
    var simpleSequence = [];
    simpleSequence = simpleList.toArray();
    //after some time add some items, to show that our binding is working
    Timeline {
        repeatCount: 1
        keyFrames: [
            KeyFrame {
                time: 5s
                canSkip: true
                action: function () {
                    //you can work on the Sequence to add or remove
                    insert "Another item" into simpleSequence;
                    //if you at some point want to have your array reflect the changes
                    //then perform your changes on that too
                    simpleList.add("Another item");
                    //remember depending on your app
                    //you may keep the update of simpleList
                    //until you are finished with this view and do it in a single update
            KeyFrame {
                time: 10s
                action: function () {
                    //Alternatly, to keep your ArrayList correct at all times
                    //add items to it and then update your Sequence
                    simpleList.add("Added to array");
                    simpleSequence = simpleList.toArray();
    }.play();
    Stage {
        title: "Application title"
        scene: Scene {
            width: 250
            height: 80
            content: [
                ListView {
                    items: bind simpleSequence
    }You can bind to a function rather than the data, which I am sure would be needed some cases, for example if the listBox data was a named part of a hash value for example, all that is required is that your function returns a sequence.

  • How to show the contents of a dropdown list with different colors

    Hi,
    I have a drop downlist on my dialog. I want to show each of its text attribute and its back ground with different color.
    Suppose I am showing 4 strings in the dropdown like Name1, Name2, Name3 and Name4, then how to change the color of each name and its background.
    Please let me know if it is possible.

    If the above asked is not possibe can we have an alternative as mentioned below :-
    A dropdown similar to the one shown in "Edit->Preferences->Grids->Colors" having our own text names instead of the default color names.
    So that I can show some color symbol and a text name along with it in my dropdown.
    One more query, is it possible to show the images/giff/png files in dropdown ?

  • How to insert the contents of a link in a div container?

    Hi,
    I try some layouts with CSS templates having sidebar. My problem is that when I click on the link (defined as <a href="my_text.htm">Link one</a> for example a new window appears with the contnets of the file. How do I select as target the container of a div tag?
    I tried some javascripts but the result is always the same, the link opens in a new window.
    Thanks in advance
    Chris

    How do I select as target the container of a div tag?
    Using the advanced features of TTM - create a div at the foot of the page. Insert your content into it.
    Link your text in TTM. to the div. Set the positioning, height and width parameters where you want the div content to be displayed on the same page.
    When the page is viewed the div at the bottom of the page is hidden.
    When the TTM link is clicked or moused over the div and its contents appear at the position you set

Maybe you are looking for