I don't know why the customer records cannot be inserted into the linked list and the head of the linked list keep pointing to null... - //ListNode.java
-
public class ListNode{
-
private Object item;
-
private ListNode next,head;
-
public ListNode(Object newItem)
-
{ item = newItem; next = null; }
-
public ListNode(Object newItem, ListNode newNext)
-
{ item = newItem; next = newNext; }
-
public void setItem(Object newItem)
-
{ item = newItem; }
-
public void setNext(ListNode newNext)
-
{ next = newNext; }
-
public Object getItem()
-
{ return item; }
-
public ListNode getNext()
-
{ return next; }}
-
-
//LinkedList.java
-
public class LinkedList{
-
protected ListNode head; //pointer to the first object
-
protected int numOfItems; //total number of objects
-
public LinkedList()
-
{ head = null; numOfItems = 0; }
-
public boolean isEmptyList(){
-
if(numOfItems==0) return true;
-
else return false; }
-
protected ListNode find(int index) {
-
ListNode cur = head;
-
if (index > numOfItems) return null;
-
for (int count=1; count<index; count++) cur = cur.getNext();
-
return cur;}
-
public boolean insert(int at, Object newItem)
-
{ ListNode pre, cur;
-
if (at < 1 || at > numOfItems+1) return false;
-
numOfItems++;
-
if (at == 1){
-
if (isEmptyList()) head = new ListNode(newItem);
-
else head = new ListNode(newItem, head);
-
return true;}
-
pre = find(at-1);
-
cur = pre.getNext();
-
pre.setNext(new ListNode(newItem, cur));
-
return true;}
-
public int size()
-
{ return numOfItems; }
-
-
//Customer.java
-
public class Customer{
-
protected int acc_id;
-
protected String name,address,birthdate,phone_no;
-
protected double balance, interest;
-
protected String type;
-
public Customer(){....} //default constructor
-
public Customer(int id,int name....){....}
-
//all the set and get methods
-
-
//Main Program
-
Customer[] records = new Customer[30];
-
LinkedList custRecords = new LinkedList();
-
for(int i=0;i<records.length;i++){ records[i] = new Customer(); }
-
//ask user for filename
-
//call readfile(filename,records,custRecords)
-
public static void readfile(String filename,Customer[] record,LinkedList cust_list){
-
int i=0;
-
try{
-
File file = new File(filename);
-
Scanner readfile = new Scanner(file);
-
while(readfile.hasNext()){
-
//read all inputs from file
-
//e,g, record[i].setID(readfile.nextInt());
-
cust_list.insert(i+1,record[i]); //Something wrong here?
-
i++;
-
}
-
}catch(FileNotFoundException){
-
System.out.println("File not found");
-
}}
3 4071
I don't know why the customer records cannot be inserted into the linked list and the head of the linked list keep pointing to null...
System.out.println() is a very good debugging tool. Sprinkle them all over your
code where you expect something fishy's going on and run your program again.
kind regards,
Jos
Thanx for ur help~ I solved the problem already~
Thanx for ur help~ I solved the problem already~
Great; care to elaborate on what the mistake was? (just for the posterity).
kind regards,
Jos
Sign in to post your reply or Sign up for a free account.
Similar topics
by: J Peterman |
last post by:
Im having a nightmare trying to understand these nodes and linked lists.
I've posted my code for my node.h, node.cpp, linkedlist.h and...
|
by: cody |
last post by:
Why isn't there a LinkedList in .NET?
Was the reason that the mark&sweep GC algorithm has problems with heavily
linked data?
A LinkedList is...
|
by: LP |
last post by:
Hi,
I was asked at the tech screening what the linked list was which I answered
with "academic" definition. Then a guy asked me how I would...
|
by: Justin Crites |
last post by:
I have an object which I want to be serializable. I have marked with
with . The object only has a single data
member, which is a LinkedList<int>....
|
by: mathon |
last post by:
Hi,
i am currently working on creating a LinkedList, for that I using a
predefined Node-class which offers a LinkedList Toolkit to manipulate...
|
by: Phillip.Ross.Taylor |
last post by:
When I designed my application I created an object called "Orderable"
which exposes a public property "sequence".
Then a few objects inherit from...
|
by: sejong510 |
last post by:
MSDN has an example of creating a LinkedList populated with String
objects:
http://msdn2.microsoft.com/en-us/library/he2s3bh7.aspx
But, how...
|
by: CaseySimplified |
last post by:
I am writing a LinkedList class from scratch without using the already defined LinkedList class. The only thing that doesn't seem to be working is...
|
by: monkey0525 |
last post by:
Hi, I'm writing a program that reverses the lines of a String using the LinkedList structure, which includes an iterator. I have my code written out,...
|
by: concettolabs |
last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
|
by: better678 |
last post by:
Question:
Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct?
Answer:
Java is an object-oriented...
|
by: jalbright99669 |
last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
|
by: antdb |
last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine
In the overall architecture, a new "hyper-convergence" concept was...
|
by: Matthew3360 |
last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function.
Here is my code.
...
|
by: Matthew3360 |
last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
|
by: AndyPSV |
last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
|
by: Arjunsri |
last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
|
by: Oralloy |
last post by:
Hello Folks,
I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA.
My problem (spelled failure) is with the...
| |