473,465 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Help on Linked Lists

35 New Member
I have a file containing all the customer records. I had a program to read from the file and store using LinkedLists. Each Node is each customer record. Each customer record have AccID, Add, PhoneNum, etc.. All the accID, add are stored in an array. My question is how can I get all the names, ids all printed out?

Expand|Select|Wrap|Line Numbers
  1. //ListNode.java
  2. public class ListNode{
  3.     private Object item;
  4.     private ListNode next,head; 
  5.  
  6.     public ListNode(Object newItem) 
  7.     {    item = newItem;    next = null;     }
  8.  
  9.     public ListNode(Object newItem, ListNode newNext)
  10.     {    item = newItem;    next = newNext;    }
  11.  
  12.     public void setItem(Object newItem)
  13.     {    item = newItem;    }
  14.  
  15.     public void setNext(ListNode newNext)
  16.     {    next = newNext;    }
  17.  
  18.     public Object getItem()
  19.     {     return item;    }
  20.  
  21.     public ListNode getNext()
  22.     {    return next;    }}
  23.  
  24. //LinkedList.java
  25. public class LinkedList{
  26.     protected ListNode head; //pointer to the first object
  27.     protected int numOfItems; //total number of objects
  28.  
  29.     public LinkedList()
  30.     {    head = null;     numOfItems = 0; }
  31.  
  32.     public boolean isEmptyList(){
  33.         if(numOfItems==0)  return true;
  34.         else    return false;    }
  35.  
  36.     protected ListNode find(int index) {    
  37.          ListNode    cur = head;
  38.          if (index > numOfItems) return null;
  39.          for (int count=1; count<index; count++)     cur = cur.getNext();
  40.          return cur;}
  41.  
  42.     public boolean insert(int at, Object newItem) 
  43.     {    ListNode    pre, cur;
  44.          if (at < 1 || at > numOfItems+1) return false;
  45.             numOfItems++;
  46.          if (at == 1){
  47.             if (isEmptyList()) head = new ListNode(newItem);
  48.             else head = new ListNode(newItem, head);
  49.             return true;}
  50.         pre = find(at-1);
  51.     cur = pre.getNext();
  52.     pre.setNext(new ListNode(newItem, cur));
  53.     return true;}
  54.  
  55.     public int size()
  56.     {    return numOfItems;    }
  57.  
  58. //Customer.java
  59. public class Customer{
  60.     protected int acc_id;
  61.     protected String name,address,birthdate,phone_no;
  62.     protected double balance, interest;
  63.     protected String type;
  64.  
  65.     public Customer(){....} //default constructor
  66.     public Customer(int id,int name....){....}
  67.     //all the set and get methods 
  68.  
  69. //Main Program
  70. Customer[] record = new Customer[30];
  71. LinkedList custRecords = new LinkedList();
  72. ListNode numRecord = new ListNode(record);
  73. while(readfile.hasNext()){ //readfile is using the Scanner class
  74. //read all the data from file
  75. //e.g. record[i].setID(readfile.nextInt());
  76.  custRecords.insert(i+1,record[i]);}
  77. //put the printing here, but how?
I use NetBeans debugger mode and found that it is in this structure:
numRecord
item
[0]
acc_id //the correct id e.g. 123
name //Matt Damon
item
[1]
acc_id //e.g. 456
name // Ben Affleck
Sep 15 '07 #1
4 1581
r035198x
13,262 MVP
Override the toString method of your Customer class then just loop through all the customers and printing their toString values.
Sep 15 '07 #2
huiling25
35 New Member
Hmm, so, i don't need to use the LinkedList() or ListNode() to help me print out the data?
Sep 15 '07 #3
r035198x
13,262 MVP
Hmm, so, i don't need to use the LinkedList() or ListNode() to help me print out the data?
No, LinkedLists are not used for printing, they are just a collection for storing many objects.
Sep 15 '07 #4
huiling25
35 New Member
No, LinkedLists are not used for printing, they are just a collection for storing many objects.
I see, thanx for all your help~
Sep 15 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Chris Ritchey | last post by:
Hmmm I might scare people away from this one just by the title, or draw people in with a chalange :) I'm writting this program in c++, however I'm using char* instead of the string class, I am...
1
by: prime80 | last post by:
I'm building a project database to keep track of the various engineering projects ongoing in our department. These projects will be grouped by priority (=High, Medium, Low) and ranked within the...
10
by: Kent | last post by:
Hi! I want to store data (of enemys in a game) as a linked list, each node will look something like the following: struct node { double x,y; // x and y position coordinates struct enemy...
1
by: Booser | last post by:
// Merge sort using circular linked list // By Jason Hall <booser108@yahoo.com> #include <stdio.h> #include <stdlib.h> #include <time.h> #include <math.h> //#define debug
12
by: Jonathan Bartlett | last post by:
Just finished a new IBM DeveloperWorks article on linked lists, and thought you all might be interested. It's not an introduction -- it instead covers some of the more interesting aspects of...
3
by: s_subbarayan | last post by:
Dear all, 1)In one of our implementation for an application we are supposed to collate two linked lists.The actual problem is like this: There are two singularly linked lists, the final output...
4
by: MJ | last post by:
Hi I have written a prog for reversing a linked list I have used globle pointer Can any one tell me how I can modify this prog so that I dont have to use extra pointer Head1. When I reverse a LL...
3
by: Little | last post by:
Could someone tell me what I am doing wrong here about declaring mutiple double linked lists. This is what the information is for the project and the code wil be below that. Thank your soo much for...
19
by: Dongsheng Ruan | last post by:
with a cell class like this: #!/usr/bin/python import sys class Cell: def __init__( self, data, next=None ): self.data = data
51
by: Joerg Schoen | last post by:
Hi folks! Everyone knows how to sort arrays (e. g. quicksort, heapsort etc.) For linked lists, mergesort is the typical choice. While I was looking for a optimized implementation of mergesort...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.