Linking List of Values
Hi,
I have two LOVs within the same region on a page
1) selects all companys User picks a company and it displays in the :company field.
2) selects all fiscal data for the specific company(:company) that was selected by the user in LOV 1.
Problem is that LOV2 can't see the value that was picked by the user even though its displayed, so it comes up null. If I navigate to another page and come back, it can see it. How can I get the company that was selected by the user in LOV1 to be seen by LOV2?
Thanks for any help.
two further examples I have used in the past are:
Denes Kubicek example app: [http://htmldb.oracle.com/pls/otn/f?p=31517:119:]
alternatively check out Patrick's ApexLib framework, I've used it in may apps and have found it to be excellent, and has the dependent LOV capability done and dusted out of the box : [http://www.inside-oracle-apex.com/update-generic-solution-for-depending-select-listspopup-lovs/]
cheers,
stu
Similar Messages
-
Recursion:returning the largest value in a linked list
import java.io.*;
import java.util.*;
class Node{
int num;
Node next;
Node(int n){
num = n;
next = null;
class RecursivePrint{
public static void main(String[] args){
Node np, last;
Node top = null;
last = null;
for(int i = 1; i <11; i++){
np = new Node(i);
if(top==null)top = np;
else
last.next = np;
last = np;
int x =Largest(top);
System.out.println("large is "+ x);
}//end main
public static int Largest(Node top){
int large = 0;
if(top==null){
return 0;
while(top!=null){
if(top.num > large){
large = top.num;
//top = top.next;
Largest(top.next);
}//while
return large;
}//end class
I am trying to return the largest value in a linked list (10) in this case. when I do it withour recurrsion it works ok, but when I try it with recurrsion it dies. The logic seems ok to me, cannot figure why it dies.chetah wrote:
public static int Largest(Node top){
int large = 0;
if(top==null){
return 0;
if(top.num > large){
large = top.num;
//top = top.next;
Largest(top.next);
return large;
Initially I had the above, it return only 1 that was the reason for puting the loop.You don't seem to understand recursion or variable scope.
int large = 0;large is a different variable inside each instance of the method.
So when you get back up to the value 1 from the recursive calls its just comparing 1 to 0
Here's a solution...
public static int Largest(Node top){
if(top.next != null){
if(Largest(top.next) > top.num)
return Largest(top.next);}
return top.num;
} -
Values of data in a linked-list
hello.
i declare a small linked list of elemets (about 10), everything is fine and dandy but i need to assign an int value to every one of those elements as a counter whenever a certain action is performed on the element in the list.
LinkedList mylist = new Linkedlist();
int value=0;
//i need to assign a unique int value to every element in the list as a counter to keep track of how many times [whatever element] is accessed, moved around, ect.
is this possible?If your linked list contains a specific type of object, add a counter to it. This may mean extending whatever the class the element is.
If you want to do theis generically, you are probably going to have to extend LinkedList and inside that class encapsulate another collection (maybe a linked list). The encapsulated collection will contain the set of counters. You will have to override all of LinkedLists methods so that you can maintain the counters. -
Restrict the list of values retrieved by a model driven LOV
hi all
i'm try to restrict the list of values retrieved by a model driven LOV just like the article in this link
http://www.oracle.com/technology/products/jdev/tips/fnimphius/restrictlovlist/restrictlov.html
and i'm using the jdev11.2 but i always get this error
java.sql.SQLException: parameter IN or OUT is missing at index 1
my code is :
public void SetSchoolLovVar(LaunchPopupEvent launchPopupEvent)
String var_val=getOt7().getValue().toString();
System.out.println("++++++++++++++++++++++++++++++++"+var_val);
BindingContext bctx = BindingContext.getCurrent();
BindingContainer bindings = bctx.getCurrentBindingsEntry();
FacesCtrlLOVBinding lov = (FacesCtrlLOVBinding)bindings.get("DeptCode");
System.out.print("LOVE "+lov);
System.out.println("+_+_+_+_+__+_+_+__+_+_+_+_+_+_+_+_+_+_________+++++_+_+_"+lov.getName());
lov.getListIterBinding().getViewObject().setNamedWhereClauseParam("Rejon_For_Prj_Dept",var_val);
Rejon_For_Prj_Dept is the bind variable of the Lov Query.
any good ideaHi,
The error might be due to making the bind variable as required but not using it in the vo query. Edit the bind variable and make it as optional by unchecking the required checkbox.
Sireesha -
Filter view object by selected values from list of values
Hello,
I've the following problem with my ADF Application. I have three view objects in my application module. Two of them are connected via a view link. For example take users, who are connected to their departments. The remaining view object consists of factories. Now I want to show the user/department dependency in a tree table and the available factories in a list of values. This list of values should be used to filter the shown users.
I've already tried to use bind variables in the users view object. But I don't know how to fill them with the value of the list of values.
Can someboy give me a tip how to solve this problem.
Best regards,
EnnoHi Enno,
Try this:
- Have a AM method with one parameter(which takes user from the list of values) and inside AM method write code to set the bind parameter value and execute the query
Sample Code
public void filterByUser(String user){
//Get your UserViewObject instance to userVO
userVO.setNamedWhereClauseParam("<Bind_Variable_Name>", user);
userVO.executeQuery();
}- Expose the method as client interface
- Drop the method (Data Control) as a button on to the page and pass the listofvalues value as a value to the method binding param
Something like this: ${bindings.<User>.inputValue}
- Finally refresh the master and detail tables based on the ListOfValues selection by setting partialTriggers property to the listofvalues component id
Hope it is clear
Sireesha
Edited by: Sireesha Pinninti on Oct 15, 2009 4:54 AM -
JSP, BC4J : Allowing users to choose from List of values when in Insert mode
Hi,
I have a requirement in which the user would be able to select a value from a combobox for populating a field when inserting a new record. The list of values in the combo box is derived from a look up table in the database. How can do this?
Thanks.Use the version provided in Jdev 3.2. It has two methods:
* Enables a LOV (list of values) for the specified attribute in
* the UI. In the typical case, when an attribute is selected in an
* HTML form, a LOV will be displayed.
* <p>
* This method enables a LOV for one or more of the RowSet's attributes.
* To return all of the RowSet's attributes,
* use the {@link #useLOV(String, String) useLOV} method.
* <p>
* @param sAtttibute name of the attribute for which an LOV
* should be enabled.
* @param voName name of the View Object to which the attribute belongs.
* @param sDisplayAttributes a comma-separated list of the RowSet's attributes
* that will be displayed when the attribute is selected.
* @param sDataAttribute the location from which the attributes' values are
* obtained.
* @see #useLOV(String, String)
public void useListOfValues(String sAttribute , String voName, String sDisplayAttributes, String sDataAttribute)
JSlibNeeded |= WebBean.JSModalPageConstructorLib;
LOVField lovField = new LOVField();
ViewObject vo = qView.getApplicationModule().findViewObject(voName);
ViewObject dupvo = qView.getApplicationModule().findViewObject(voName + "_query");
if(dupvo == null)
dupvo = qView.getApplicationModule().createViewObject(vo.getName() + "_query", vo.getDefFullName());
lovField.setViewObject(getApplicationName() + "." + dupvo.getName());
AttributeDef attr = qView.getViewObject().findAttributeDef(sAttribute);
lovField.setPromptText(getAttributeLabel(qView, attr));
lovField.setDisplayAttributes(sDisplayAttributes);
lovField.setDataAttributes(sDataAttribute);
setFieldRenderer(sAttribute , lovField);
* Enables a LOV (list of values) for the specified attribute in the UI.
* In the typical case, when the specified attribute is selected in an
* HTML form, a LOV will be displayed.
* <p>
* This method enables a LOV for all of the RowSet's attributes.
* To enable a LOV for a subset of the attributes,
* use the {@link #useListOfValues(String, String, String, String)
* useListOfValues} method.
* <p>
* @param sAtttibute name of the attribute for which an LOV
* should be enabled.
* @param voName name of the View Object to which the attribute belongs.
* @see #useListOfValues(String, String, String, String)
public void useLOV(String sAttribute, String voName)
useListOfValues(sAttribute, voName, null, sAttribute);
null -
How create temporary table from list of values
Can you anybody advise me how can I create temporary table from list of values? I have list of values and need create temporary table for next use with command JOIN etc.
Thank you for helpNO, you can not create temporary table in oracle on the fly ( Like #Tabels in SQl Server or Sybase ) , you will have to use the GTT i.e Global Temporary Tables
check the following link GTT :
to flush the tables after commit
CREATE GLOBAL TEMPORARY TABLE my_temp_table (
column1 NUMBER,
column2 NUMBER
) ON COMMIT DELETE ROWS;In contrast, the ON COMMIT PRESERVE ROWS clause indicates that rows should be preserved until the end of the session.
so to keep rows in Table after commit
CREATE GLOBAL TEMPORARY TABLE my_temp_table (
column1 NUMBER,
column2 NUMBER
) ON COMMIT PRESERVE ROWS; -
Need help regarding Linked List
I'm a beginner who just spent ages working on the following code.. but need help on re-implementing the following using a linked list, i.e. no array is allowed for customer records but you still can use arrays for names, address, etc.. Hopefully I've inserted enough comments..
Help very much appreciated!! Thanks! =]
import java.util.Scanner;
import java.io.*;
public class Bank
/* Private variables declared so that the data is only accessible to its own
class, but not to any other class, thus preventing other classes from
referring to the data directly */
private static Customer[] customerList = new Customer[30];
//Array of 30 objects created for storing information of each customer
private static int noOfCustomers;
//Integer used to store number of customers in customerList
public static void main(String[] args)
Scanner sc = new Scanner(System.in);
menu();
public static void menu()
char choice;
String filename;
int custId,counter=0;
double interestRate;
Scanner sc = new Scanner(System.in);
do
//Displaying of Program Menu for user to choose
System.out.println("ABC Bank Customer Management System Menu");
System.out.println("========================================");
System.out.println("(1) Input Data from File");
System.out.println("(2) Display Data");
System.out.println("(3) Output Data to File");
System.out.println("(4) Delete Record");
System.out.println("(5) Update Record");
System.out.println("(Q) Quit");
System.out.println();
System.out.print("Enter your choice: ");
String input = sc.next();
System.out.println();
choice = input.charAt(0);
//switch statement used to assign each 'selection' to its 'operation'
switch(choice)
case '1': int noOfRecords;
System.out.print("Enter file name: ");
sc.nextLine();
filename = sc.nextLine();
System.out.println();
noOfRecords = readFile(filename);
System.out.println(+noOfRecords+" records read.");
break;
case '2': displayRecords();
break;
case '3': writeFile();
break;
case '4': System.out.print("Enter account ID to be deleted: ");
sc.nextLine();
custId = sc.nextInt();
deleteRecord(custId);
break;
case '5': if(counter==0)
System.out.print("Enter current interest rate for saving account: ");
sc.nextLine();
interestRate = sc.nextDouble();
update(interestRate);
counter++;
else
System.out.println("Error: Accounts have been updated for the month.");
break;
}System.out.println();
}while(choice!='Q' && choice!='q');
/* The method readFile() loads the customer list of a Bank from a specified
text file fileName into customerList to be stored as array of Customer
objects in customerList in ascending alphabetical order according to the
customer names */
public static int readFile(String fileName)
int custId,i=0;
String custName,custAddress,custBirthdate,custPhone,custAccType;
double custBalance,curRate;
boolean d;
/* Try block to enclose statements that might throw an exception, followed by
the catch block to handle the exception */
try
Scanner sc = new Scanner(new File(fileName));
while(sc.hasNext())
/* sc.next() gets rid of "Account", "Id" and "=" */
sc.next();sc.next();sc.next();
custId = sc.nextInt();
d=checkDuplicate(custId);
/* checkDuplicate() is a method created to locate duplicating ids in array */
if(d==true)
/* A return value of true indicates duplicating record and the sc.nextLine()
will get rid of all the following lines to read the next customer's record */
sc.nextLine();sc.nextLine();sc.nextLine();
sc.nextLine();sc.nextLine();sc.nextLine();
continue;
/* A return value of false indicates no duplicating record and the following
lines containing the information of that customer's record is being read
in */
if(d==false)
/* sc.next() gets rid of "Name" and "=" and name is changed to upper case*/
sc.next();sc.next();
custName = sc.nextLine().toUpperCase();
/* sc.nextLine get rids of the following lines to read the next customer's
record if length of name is more than 20 characters*/
if(custName.length()>21)
System.out.println("Name of custId "+custId+" is more than 20 characters");
System.out.println();
sc.nextLine();sc.nextLine();sc.nextLine();sc.nextLine();
continue;
/* sc.next() gets rid of "Address" and "=" */
sc.next();sc.next();
custAddress = sc.nextLine();
/* sc.nextLine get rids of the following lines to read the next customer's
record if length of address is more than 80 characters*/
if(custAddress.length()>81)
System.out.println("Address of custId "+custId+" is more than 80 characters");
System.out.println();
sc.nextLine();sc.nextLine();sc.nextLine();sc.nextLine();
continue;
/* sc.next() gets rid of "DOB" and "=" */
sc.next();sc.next();
custBirthdate = sc.nextLine();
/* sc.nextLine get rids of the following lines to read the next customer's
record if length of date of birth is more than 10 characters*/
if(custBirthdate.length()>11)
System.out.println("D.O.B of custId "+custId+" is more than 10 characters");
System.out.println();
sc.nextLine();sc.nextLine();sc.nextLine();sc.nextLine();
continue;
/* sc.next() gets rid of "Phone", "Number" and "=" */
sc.next();sc.next();sc.next();
custPhone = sc.nextLine();
/* sc.nextLine get rids of the following lines to read the next customer's
record if length of phone number is more than 8 characters*/
if(custPhone.length()>9)
System.out.println("Phone no. of custId "+custId+" is more than 8 characters");
System.out.println();
sc.nextLine();sc.nextLine();sc.nextLine();sc.nextLine();
continue;
/* sc.next() gets rid of "Account", "Balance" and "=" */
sc.next();sc.next();sc.next();
custBalance = sc.nextDouble();
/* sc.next() gets rid of "Account", "Type" and "=" */
sc.next();sc.next();sc.next();
custAccType = sc.next();
if(custAccType.equals("Saving"))
customerList[noOfCustomers] = new Account1(custId,custName,custAddress,custBirthdate,custPhone,custBalance,custAccType);
sc.nextLine();
noOfCustomers++;
i++;
else if(custAccType.equals("Checking"))
customerList[noOfCustomers] = new Account2(custId,custName,custAddress,custBirthdate,custPhone,custBalance,custAccType);
sc.nextLine();
noOfCustomers++;
i++;
else if(custAccType.equals("Fixed"))
sc.next();sc.next();sc.next();sc.next();
curRate = sc.nextDouble();
Account3 temp = new Account3(custId,custName,custAddress,custBirthdate,custPhone,custBalance,custAccType,curRate);
customerList[noOfCustomers]=temp;
sc.nextLine();
noOfCustomers++;
i++;
else
System.out.println("Account type not defined.");
if(noOfCustomers==30)
System.out.println("The customer list has reached its maximum limit of 30 records!");
System.out.println();
return noOfCustomers;
//Exceptions to be caught
catch (FileNotFoundException e)
System.out.println("Error opening file");
System.exit(0);
catch (IOException e)
System.out.println("IO error!");
System.exit(0);
/* Bubblesort method used to sort the array in ascending alphabetical order
according to customer's name */
bubbleSort(customerList);
return i;
/* The method displayRecords() displays the data of the customer records on
screen */
public static void displayRecords()
int k;
/* Displaying text using the printf() method */
for(k=0;k<noOfCustomers;k++)
System.out.printf("Name = %s\n", customerList[k].getName());
System.out.printf("Account Balance = %.2f\n", customerList[k].getBalance());
System.out.printf("Account Id = %d\n", customerList[k].getId());
System.out.printf("Address = %s\n", customerList[k].getAddress());
System.out.printf("DOB = %s\n", customerList[k].getBirthdate());
System.out.printf("Phone Number = %s\n", customerList[k].getPhone());
String type = customerList[k].getAccType();
System.out.println("Account Type = " +type);
if(type.equals("Fixed"))
System.out.println("Fixed daily interest = "+((Account3)customerList[k]).getFixed());
System.out.println();
/* The method writeFile() saves the content from customerList into a
specified text file. Data is printed on the screen at the same time */
public static void writeFile()
/* Try block to enclose statements that might throw an exception, followed by
the catch block to handle the exception */
try
int i;
int n=0;
//PrintWriter class used to write contents of studentList to specified file
FileWriter fwStream = new FileWriter("newCustomers.txt");
BufferedWriter bwStream = new BufferedWriter(fwStream);
PrintWriter pwStream = new PrintWriter(bwStream);
for(i=0;i<noOfCustomers;i++)
pwStream.println("Account Id = "+customerList.getId());
pwStream.println("Name = "+customerList[i].getName());
pwStream.println("Address = "+customerList[i].getAddress());
pwStream.println("DOB = "+customerList[i].getBirthdate());
pwStream.println("Phone Number = "+customerList[i].getPhone());
pwStream.printf("Account Balance = %.2f\n", customerList[i].getBalance());
pwStream.println("Account Type = "+customerList[i].getAccType());
if(customerList[i].getAccType().equals("Fixed"))
pwStream.println("Fixed Daily Interest = "+((Account3)customerList[i]).getFixed());
pwStream.println();
n++;
//Closure of stream
pwStream.close();
System.out.println(+n+" records written.");
catch(IOException e)
System.out.println("IO error!");
System.exit(0);
//Deletes specified record from list
public static void deleteRecord(int id)
int i;
i=locate(id);
if(i==200)
//checking if account to be deleted does not exist
System.out.println("Error: no account with the id of "+id+" found!");
//if account exists
else
while(i<noOfCustomers)
customerList[i] = customerList[i+1];
i++;
System.out.println("Account Id: "+id+" has been deleted");
--noOfCustomers;
//Updates the accounts
public static void update(double interest)
int i,j,k;
double custBalance,addition=0;
for(i=0;i<noOfCustomers;i++)
if(customerList[i] instanceof Account1)
for(j=0;j<30;j++)
addition=customerList[i].getBalance()*interest;
custBalance=customerList[i].getBalance()+addition;
customerList[i].setBalance(custBalance);
else if(customerList[i] instanceof Account2)
continue;
else if(customerList[i] instanceof Account3)
for(j=0;j<30;j++)
addition=customerList[i].getBalance()*((Account3)customerList[i]).getFixed();
custBalance=customerList[i].getBalance()+addition;
customerList[i].setBalance(custBalance);
else
System.out.println("Account type not defined");
System.out.println("The updated balances are: \n");
for(k=0;k<noOfCustomers;k++)
System.out.printf("Name = %s\n", customerList[k].getName());
System.out.printf("Account Balance = %.2f\n", customerList[k].getBalance());
System.out.println();
/* ================== Additional methods ==================== */
/* Bubblesort method to sort the customerList in ascending alphabetical
order according to customer's name */
public static void bubbleSort(Customer[] x)
int pass, index;
Customer tempValue;
for(pass=0; pass<noOfCustomers-1; pass++)
for(index=0; index<noOfCustomers-1; index++)
if(customerList[index].getName().compareToIgnoreCase(customerList[index+1].getName()) > 0)
tempValue = x[index];
x[index] = x[index+1];
x[index+1]= tempValue;
/* Method used to check for duplicated ids in array */
public static boolean checkDuplicate(int id)
int i;
for(i=0;i<noOfCustomers;i++)
if(id == customerList[i].getId())
System.out.println("Account Id = "+id+" already exists");
System.out.println();
return true;
}return false;
/* Method to seach for account id in array */
public static int locate(int id)
int j;
for(j=0;j<noOfCustomers;j++)
if(customerList[j].getId()==id)
return j;
j=200;
return j;
import java.util.Scanner;
public class Customer
/* The following private variables are declared so that the data is only
accessible to its own class,but not to any other class, thus preventing
other classes from referring to the data directly */
protected int id;
protected String name,address,birthdate,phone,accType;
protected double balance;
// Null constructor of Customer
public Customer()
id = 0;
name = null;
address = null;
birthdate = null;
phone = null;
balance = 0;
accType = null;
/* The following statements with the keyword this activates the Customer
(int id, String name String address, String birthdate, String phone, double
balance) constructor that has six parameters of account id, name, address,
date of birth, phone number, account balance and assign the values of the
parameters to the instance variables of the object */
public Customer(int id, String name, String address, String birthdate, String phone, double balance, String accType)
//this is the object reference that stores the receiver object
this.id = id;
this.name = name;
this.address = address;
this.birthdate = birthdate;
this.phone = phone;
this.balance = balance;
this.accType = accType;
/* The following get methods getId(), getName(), getAddress(), getBirthdate(),
getPhone(), getBalance() return the values of the corresponding instance
properties */
public int getId()
return id;
public String getName()
return name;
public String getAddress()
return address;
public String getBirthdate()
return birthdate;
public String getPhone()
return phone;
public double getBalance()
return balance;
public String getAccType()
return accType;
/* The following set methods setId(), setName(), setAddress(), setBirthdate(),
setPhone and setBalance() set the values of the corresponding instance
properties */
public void setId (int custId)
id = custId;
public void setName(String custName)
name = custName;
public void setAddress (String custAddress)
address = custAddress;
public void setBirthdate (String custBirthdate)
birthdate = custBirthdate;
public void setPhone (String custPhone)
phone = custPhone;
public void setBalance (double custBalance)
balance = custBalance;
public void setAccType (String custAccType)
accType = custAccType;
class Account1 extends Customer
public Account1(int id, String name, String address, String birthdate, String phone, double balance, String accType)
super(id,name,address,birthdate,phone,balance,accType);
this.id = id;
this.name = name;
this.address = address;
this.birthdate = birthdate;
this.phone = phone;
this.balance = balance;
this.accType = accType;
class Account2 extends Customer
public Account2(int id, String name, String address, String birthdate, String phone, double balance, String accType)
super(id,name,address,birthdate,phone,balance,accType);
this.id = id;
this.name = name;
this.address = address;
this.birthdate = birthdate;
this.phone = phone;
this.balance = balance;
this.accType = accType;
class Account3 extends Customer
protected double fixed=0;
public Account3(int id, String name, String address, String birthdate, String phone, double balance, String accType, double fixed)
super(id,name,address,birthdate,phone,balance,accType);
this.id = id;
this.name = name;
this.address = address;
this.birthdate = birthdate;
this.phone = phone;
this.balance = balance;
this.accType = accType;
this.fixed = fixed;
public double getFixed()
return fixed;
Example of a customers.txt
Account Id = 123
Name = Matt Damon
Address = 465 Ripley Boulevard, Oscar Mansion, Singapore 7666322
DOB = 10-10-1970
Phone Number = 790-3233
Account Balance = 405600.00
Account Type = Fixed
Fixed Daily Interest = 0.05
Account Id = 126
Name = Ben Affleck
Address = 200 Hunting Street, Singapore 784563
DOB = 25-10-1968
Phone Number = 432-4579
Account Balance = 530045.00
Account Type = Saving
Account Id = 65
Name = Salma Hayek
Address = 45 Mexican Boulevard, Hotel California, Singapore 467822
DOB = 06-04-73
Phone Number = 790-0000
Account Balance = 2345.00
Account Type = Checking
Account Id = 78
Name = Phua Chu Kang
Address = 50 PCK Avenue, Singapore 639798
DOB = 11-08-64
Phone Number = 345-6780
Account Balance = 0.00
Account Type = Checking
Account Id = 234
Name = Zoe Tay
Address = 100 Blue Eyed St, Singapore 456872
DOB = 15-02-68
Phone Number = 456-1234
Account Balance = 600.00
Account Type = Saving1) When you post code, please use[code] and [/code] tags as described in Formatting tips on the message entry page. It makes it much easier to read.
2) Don't just post a huge pile of code and ask, "How do I make this work?" Ask a specific question, and post just enough code to demonstrate the problem you're having.
3) Don't just write a huge pile of code and then test it. Write a tiny piece, test it. Then write the piece that will work with or use the first piece. Test that by itself--without the first piece. Then put the two together and test that. Only move on to the next step after the current step produces the correct results. Continue this process until you have a complete, working program. -
Help needed in linked lists...
I have been working on this computer assignment lately but I still don't understand linked lists yet..I did an assignment on array based implementation and now I am supposed to do the same thing in linked list implementation..
I need help on how to change this into a linked list implementation..any help would be appreciated. Thank you..below is the code for the array based implementation..the only thing that needs change here is after where is says Array-based implementation of the ADT list.
public class ListArrayBasedDriver {
public static void main(String [] args) {
ListArrayBased myGroceryList = new ListArrayBased();
myGroceryList.add(1,"milk");
myGroceryList.add(2,"eggs");
myGroceryList.add(3,"butter");
myGroceryList.add(4,"pecans");
myGroceryList.add(5,"apples");
myGroceryList.add(6,"bread");
myGroceryList.add(7,"chicken");
myGroceryList.add(8,"rice");
myGroceryList.add(9,"red beans");
myGroceryList.add(10,"sausage");
myGroceryList.add(11,"flour");
printList(myGroceryList); //print out original List
System.out.print("numItems is now: " + myGroceryList.size() + "\n");
System.out.println("adding juice for 5th item...");
myGroceryList.add (5, (Object) "juice"); //add juice
System.out.println("item 5 is: " + myGroceryList.get(5)); //get position 5
printList(myGroceryList);
System.out.print("numItems is now: " + myGroceryList.size() + "\n");
System.out.println("removing juice...");
myGroceryList.remove (5); //remove item at position 5
printList(myGroceryList);
System.out.print("numItems is now: " + myGroceryList.size() + "\n");
public static void printList(ListArrayBased myList)
//method prints a list, numbering the values, e.g, "1. milk" .... "5. juice".... etc.
int i;
for(i=1; i <= myList.size(); i++)
String tempString = new String((String)myList.get(i));
System.out.println(i+" "+ tempString);
// Array-based implementation of the ADT list.
class ListArrayBased {
private static final int MAX_LIST = 50;
private Object items[]; // an array of list items
private int numItems; // number of items in list
public ListArrayBased()
// creates an empty list
items = new Object[MAX_LIST];
numItems = 0;
} // end default constructor
public boolean isEmpty()
return (numItems == 0);
} // end isEmpty
public int size()
return numItems;
} // end size
public void removeAll()
// Creates a new array; marks old array for
// garbage collection.
items = new Object[MAX_LIST];
numItems = 0;
} // end removeAll
public void add(int index, Object item) throws ListIndexOutOfBoundsException
if (numItems > MAX_LIST)
throw new ListException("ListException on add");
} // end if
if (index >= 1 && index <= numItems+1)
// make room for new element by shifting all items at
// positions >= index toward the end of the
// list (no shift if index == numItems+1)
for (int pos = numItems; pos >= index; pos--) {
items[translate(pos+1)] = items[translate(pos)];
} // end for
// insert new item
items[translate(index)] = item;
numItems++;
else
{ // index out of range
throw new ListIndexOutOfBoundsException(
"ListIndexOutOfBoundsException on add");
} // end if
} //end add
public Object get(int index) throws ListIndexOutOfBoundsException
if (index >= 1 && index <= numItems)
return items[translate(index)];
else
{ // index out of range
throw new ListIndexOutOfBoundsException(
"ListIndexOutOfBoundsException on get");
} // end if
} // end get
public void remove(int index) throws ListIndexOutOfBoundsException
if (index >= 1 && index <= numItems)
// delete item by shifting all items at
// positions > index toward the beginning of the list
// (no shift if index == size)
for (int pos = index+1; pos <= size(); pos++) {
items[translate(pos-1)] = items[translate(pos)];
} // end for
numItems--;
else
{ // index out of range
throw new ListIndexOutOfBoundsException("ListIndexOutOfBoundsException on remove");
} // end if
} // end remove
private int translate(int position) {
return position - 1;
} // end translate
} // end ListArrayBased
class ListException extends RuntimeException
public ListException(String s)
super(s);
} // end constructor
} // end ListException
class ListIndexOutOfBoundsException
extends IndexOutOfBoundsException {
public ListIndexOutOfBoundsException(String s) {
super(s);
} // end constructor
} // end ListIndexOutOfBoundsExceptionCould someone check for me if this will work and if it doesn't what I need to do to make it work..Thanks...
public class ListArrayBasedDriver {
public static void main(String [] args) {
ListArrayBased myGroceryList = new ListArrayBased();
myGroceryList.add(1,"milk");
myGroceryList.add(2,"eggs");
myGroceryList.add(3,"butter");
myGroceryList.add(4,"pecans");
myGroceryList.add(5,"apples");
myGroceryList.add(6,"bread");
myGroceryList.add(7,"chicken");
myGroceryList.add(8,"rice");
myGroceryList.add(9,"red beans");
myGroceryList.add(10,"sausage");
myGroceryList.add(11,"flour");
printList(myGroceryList); //print out original List
System.out.print("numItems is now: " + myGroceryList.size() + "\n");
System.out.println("adding juice for 5th item...");
myGroceryList.add (5, (Object) "juice"); //add juice
System.out.println("item 5 is: " + myGroceryList.get(5)); //get position 5
printList(myGroceryList);
System.out.print("numItems is now: " + myGroceryList.size() + "\n");
System.out.println("removing juice...");
myGroceryList.remove (5); //remove item at position 5
printList(myGroceryList);
System.out.print("numItems is now: " + myGroceryList.size() + "\n");
public static void printList(ListArrayBased myList)
//method prints a list, numbering the values, e.g, "1. milk" .... "5. juice".... etc.
int i;
for(i=1; i <= myList.size(); i++)
String tempString = new String((String)myList.get(i));
System.out.println(i+" "+ tempString);
// Linked List-based implementation of the ADT list.
class ListNode
//class to represent one node in a list
class ListNode
//package access members; List can access these directly
Object data;
ListNode nextNode;
//contructor creates a ListNode that refers to object
ListNode( Object object)
this( object, null );
} //end ListNode one-argument constructor
//constructor creates ListNode that refers to
// Object and to the next ListNode
ListNode ( Object object, ListNode node)
data = object;
nextNode = node;
// end ListNode two-argument contructor
//return reference to data in node
Object getObject()
return data; // return Object in this mode
//return reference to next node in list
ListNode getNext()
return nextNode; // get next node
} // end method getNext
} //end class ListNode
//class List Definition
public class List
private ListNode firstNode;
private ListNode lastNode;
private String name; // string like " list " used in printing
//contructor creates empty List with " list " as the name
public List()
this(" list ");
} //end List no-arguement constructor
//contructor creates an empty list with a name
public List( String listName )
name = listname;
firstNode = lastNode = null;
} //end List no-arguement contructor
//insert Object at front of List
public void insertAtFront ( object insertItem )
if ( isEmpty() ) //firstNode and lastNode refer to same object
firstNode = lastNode = newListNode( insertItem );
else // firstNode refers to new node
firstNode = new ListNode ( insertItem, firstNode );
} // end method insertAtFront
// insert Object at end of List
public void insert AtBack ( Object insertItem )
if ( isEmpty() ) //firstNode and lastNode refer to same object
firstNode = new ListNode ( insertItem );
else // firstNode refers to new node
firstNode = new ListNode (insertItem, firstNode );
} // end method insertAtFront
// insert Object at end of List
public void insertAtBack ( Object insertItem )
if ( isEmpty() ) //firstNode and LastNode refer to same Object
firstNode = lastNode = new ListNode ( insertItem );
else // lastNode = lastNode.nextNode = new ListNode ( insertItem );
} // end method insertAtBack
//remove first node from List
public Object removeFromFront() throws EmptyListException
if( isEmpty() ) //throw exception if list is empty
throw new EmptyListException( name );
object removedItem = firstNode.data; //retrieve data being removed
// update references firstNode and lastNode
if (firstNode == lastNode )
firstNode =lastNode = null;
else
firstNode = firstNode.nextNode;
return removedItem; // return removed node data
} //end method removeFromFront
//remove last node from List
Public Object removeFromBack() throws EmptyListException
If ( isEmpty() ) // throw exception if list is empty
throw new EmptyListException( name );
Object removedItem = lastNode.data; // retrieve data being removed
// update references firstNode and lastNode
If ( firstNode == lastNode )
firstNode = lastNode = null;
else // locate new last node
ListNode current = firstNode;
// loop while current node does not refer to lastNode
while ( current.nextNode != lastNode )
current = current.nextNode;
lastNode = current; // current is new lastNode
current.nextNode = null;
} // end else
return removedItem; // return removed node data
} // end method removeFromBack
// determine whether list is empty
public boolean isEmpty()
return firstNode == null; // return true if list is empty
} // end method isEmpty
//output List contents
public void print()
if (isEmpty() )
System.out.printf(�Empty %s\n�, name );
return;
System.out.printf(�The %s is: �, name );
ListNode current = firstNode;
//while (current != null )
System.out,printf(�%s �, current.data );
current = current.nextNode;
} //end while
System.out.println( �\n� );
} //end method print
} end class List -
How to populate form fields by choosing a parameter from a list of values?
I have a unique field (say claim #)that is displayed at the top right of the page. Whenever I choose a value from the list of values and query the DB, all the subsequent forms(representation of one or more tables, linked by claim#) present below the search field should be populated with apt values.
The issue here is, the forms displayed in the bottom of the page represent different master tables linked by the universal identifier(claim#) for my system.
Please guide me if anyone knows a solution for this issue.
Regards
ArunYou might want to look at the Acrobat Forms Data Format (FDF) Toolkit to create an FDF file that has the webbased PDF form refereced as the form source for the FDF data. You could also look at PDFTK and PDF Hacks.
This is more of a developers issue than a simple Acrobat JavaScript issue.
If may salary were to be doubled, I would still receive the same amount.
If you do not like the responses ask for double your fee back.
What do you expect for free? -
Changing data in a linked list object.
hi,
i'm still pretty new to java, so bear with me if i am making stupid mistakes, heh.
i'm having trouble with changing data in an object stored in a singly-linked list. i've created a class that will store polynomials in sorted order (descending) in a singly-linked list. each linked list is one polynomial, and each node references to a polynomial object that stores two ints: the coefficient and the exponent of that term.
i'm having trouble when it comes to 'collecting like terms,' though. here's a rough skeleton of my code:
public class Polynomial
private LinkedList polynoList;
private LinkedListItr Itr;
private int coeff;
private int exponent;
public Polynomial()
zeroPolynomial();
} // this constructor sets up an empty linked list
public Polynomial( int c, int e )
coeff = c;
exponent = e;
} // this creates a Polynomial object storing the two ints
public void zeroPolynomial()
polynoList = new LinkedList();
theItr = polynoList.zeroth();
} // this method creates the empty linked list and sets the
//iterator on the zeroth node.
//various other methods are here, not relevant to my post
//this next method is the one i am having trouble with.
//it takes two ints as parameters, the coefficient
//and the exponent.
public void insertTerm( int c, int e )
//...i have a few if/then statements here
//so that the terms can be inserted in descending order.
LinkedListItr tester = polynoList.first();
//the 'tester' iterator is set on the first node
//this following if statement retrieves the exponent
//in the current node by casting the information
//retrieved from the LinkedList retrieve() method
//into Polynomial, then compares it to the current
//exponent. if they are equal, i want to add the
//coefficients.
if( e == ((Polynomial)tester.retrieve()).getExp() )
this.coeff = ((Polynomial)tester.retrieve()).getCoeff() + c;
//a main method goes here wherein the user can insert
//terms, print the polynomial, etc.
}//end Polynomial class
can anyone help me out? the code i'm using compiles correctly, but it does not change the value of the current coeff variable as i'd like to think it should. any input would be GREATLY appreciated, thanks!hey,
thanks for the reply...
i am sure that ((Polynomial)tester.retrieve()).getExp() will return an int equal to 'e.' i tried this:
System.out.println("e="+e);
System.out.println((Polynomial)tester.retrieve()).getExp());
if( e == ((Polynomial)tester.retrieve()).getExp() ){
this.coeff = ((Polynomial)tester.retrieve()).getCoeff() + c;
System.out.println( "this.coeff = " + this.coeff );
with that, the output showed that e and the getExp() output were the same. it also showed (as output) that this.coeff did change in value, but when i tried this:
System.out.println( ((Polynomial)tester.retrieve()).getCoeff() )
to check if the value changed within the object, it didn't. this.coeff changed, but the actual coeff variable in the object didn't.
any ideas? -
Inserting integers in a Linked list/List in Java
Please solve the following problem using Java.
Problem: Write a program that inserts 25 random integers from 0 to 100 in order in a linked list object. The program should calculate the sum of the elements and the floating-point average of the elements.
Thanks
Ripondo the following 25 times
. insert random value between x and y into my list
All you have to do is replace x and y with your values and compile using the java -idiot option. -
Errors executing bulk query when updating a Sharepoint Linked List from Access
Hi all,
I have a Sharepoint list that is a Linked List with MS Access. It has just under 5,000 items (4,864), thus meaning it avoids the reduction in functionality lists of greater than 5,000 items have.
Among the list are five calculated columns. These take the information from another column (different employee numbers), and by using a formula produce a clickable link to my company's Directory page, where that particular employee's info is displayed. I'm
not sure if these five columns are relevant to my query, but I'm mentioning them in case.
My problem is this: Frequently when I run any query on the list that updates the list, I get this error: "There were errors executing the bulk query or sending the data to the server. Reconnect the tables to resolve the
conflicts or discard the pending changes".
When I review the errors, it says they conflict with errors a previous user made (with that previous user being me). It frequently highlights several columns, despite the info in them being identical, and the calculated columns (with the original showing
the value they contained and the new showing #VALUE! (as Access can't display the formulas).
However, if I click Retry All Changes, all the update stick and everything seems fine. Why is this happening? It's proving very annoying and is really stopping the automation of my large number of queries. A list of 5000 items isn't particular big (and they've
got roughly 100 columns, although I didn't think that was too large either, given Excel's 200+ column limit).
Is this due to poor query design and SQL? Is this due to connectivity issues (which I doubt, as my line seems perfect)? Is this due to Access tripping over itself and not executing the update on each row in the table, but rather executing them concurrently
and locking itself up? I'm at wit's end about it and really need to get this sorted.
Thanks in advance for any suggestions.Hi amartin903,
According to your description, my understanding is that you got an error when you used a linked list from Access.
The table that you are updating is a linked table that does not have a primary key or a unique index. Or, the query or the form is based on a linked table that does not have a primary key or a unique index. Please add the primary key or a unique index.
Here is a similar post, please take a look at:
http://social.technet.microsoft.com/Forums/en-US/545601e9-a703-4a02-8ed9-199f1ce9dac8/updating-sharepoint-list-from-access?forum=sharepointdevelopmentlegacy
I hope this helps.
Thanks,
Wendy
Wendy Li
TechNet Community Support -
Hi guys!
I read the manual of java 2 and says that is not that pointers don't exist, they do exist but they are not explicit as they are in C languagge. So in need to create a circular linked list how can I do this? The instructions of the manual are not so clear. Does anyone have an idea and can give me a sample code?
Thanks to all
MaddyReferences are like pointers except that you cannot make any add operation on them. But you can of course change their values to make it point to other objects.
This also means that you can create graph objects and every data structure you like. For example :
class BinaryNode {
public Object data;
public BinaryNode left;
public BinaryNode right;
}To create binary trees or
class GraphNode {
public Object data;
public ArrayList links;
}Where links is a Java list containing a list of links (references) to other GraphNode.
Matthieu -
Splitting a Linked List at a Given Node, into Two Sublists??
My code just will not work!! Any help would be appreciated! My problem is in the last method SplitAt. These are the conditions set and my code:
Splitting a Linked List at a Given Node, into Two Sublists
a. Add the following as an abstract method to the class
LinkedListClass:
public void splitAt (LinkedListClass<T> secondList, T item);
//This method splits the list at the node with the info item into two sublists.
//Precondition: The list must exist.
//Postcondition: first and last point to the first and last nodes of the first sublist,
// respectively. secondList.first and secondList.last point to the first
// and last nodes of the second sublist.
Consider the following statements:
UnorderedLinkedList<Integer> myList;
UnorderedLinkedList<Integer> otherList;
Suppose myList points to the list with the elements 34, 65, 18, 39, 27, 89, and 12 (in this order). The statement
myList.splitAt(otherList, 18);
splits myList into two sublists: myList points to the list with elements 34 and 65, and otherList points to the sublist with elements 18, 39, 27, 89, and 12.
b. Provide the definition of the method splitAt in the class UnorderedLinkedList. Also write a program to test your method.
public class UnorderedLinkedList<T> extends LinkedListClass<T>
//Default constructor
public UnorderedLinkedList()
super();
//Method to determine whether searchItem is in
//the list.
//Postcondition: Returns true if searchItem is found
// in the list; false otherwise.
public boolean search(T searchItem)
LinkedListNode<T> current; //variable to traverse
//the list
boolean found;
current = first; //set current to point to the first
//node in the list
found = false; //set found to false
while (current != null && !found) //search the list
if (current.info.equals(searchItem)) //item is found
found = true;
else
current = current.link; //make current point to
//the next node
return found;
//Method to insert newItem in the list.
//Postcondition: first points to the new list
// and newItem is inserted at the
// beginning of the list. Also,
// last points to the last node and
// count is incremented by 1.
public void insertFirst(T newItem)
LinkedListNode<T> newNode; //variable to create the
//new node
newNode =
new LinkedListNode<T>(newItem, first); //create and
//insert newNode before
//first
first = newNode; //make first point to the
//actual first node
if (last == null) //if the list was empty, newNode is
//also the last node in the list
last = newNode;
count++; //increment count
//Method to insert newItem at the end of the list.
//Postcondition: first points to the new list and
// newItem is inserted at the end
// of the list. Also, last points to
// the last node and
// count is incremented by 1.
public void insertLast(T newItem)
LinkedListNode newNode; //variable to create the
//new node
newNode =
new LinkedListNode(newItem, null); //create newNode
if (first == null) //if the list is empty, newNode is
//both the first and last node
first = newNode;
last = newNode;
else //if the list is not empty, insert
//newNode after last
last.link = newNode; //insert newNode after last
last = newNode; //set last to point to the
//actual last node
count++;
}//end insertLast
//Method to delete deleteItem from the list.
//Postcondition: If found, the node containing
// deleteItem is deleted from the
// list. Also, first points to the first
// node, last points to the last
// node of the updated list, and count
// is decremented by 1.
public void deleteNode(T deleteItem)
LinkedListNode<T> current; //variable to traverse
//the list
LinkedListNode<T> trailCurrent; //variable just
//before current
boolean found;
if ( first == null) //Case 1; the list is empty
System.err.println("Cannot delete from an empty "
+ "list.");
else
if (first.info.equals(deleteItem)) //Case 2
first = first.link;
if (first == null) //the list had only one node
last = null;
count--;
else //search the list for the given info
found = false;
trailCurrent = first; //set trailCurrent to
//point to the first node
current = first.link; //set current to point to
//the second node
while (current != null && !found)
if (current.info.equals(deleteItem))
found = true;
else
trailCurrent = current;
current = current.link;
}//end while
if (found) //Case 3; if found, delete the node
count--;
trailCurrent.link = current.link;
if (last == current) //node to be deleted
//was the last node
last = trailCurrent; //update the value
//of last
else
System.out.println("Item to be deleted is "
+ "not in the list.");
}//end else
}//end else
}//end deleteNode
public void splitAt(LinkedListClass<T> secondList, T item)
LinkedListNode<T> current;
LinkedListNode<T> trailCurrent;
int i;
boolean found;
if (first==null)
System.out.println("Empty.");
first=null;
last=null;
count--;
else
current=first;
found=false;
i=1;
while(current !=null &&!found)
if(current.info.equals(secondList))
found= true;
else
trailCurrent=current;
i++;
if(found)
if(first==current)
first=first;
last=last;
count=count;
count=0;
else
first=current;
last=last;
last=null;
count = count- i+1;
count = i-1;
else
System.out.println("Item to be split at is "
+ "not in the list.");
first=null;
last=null;
count=0;
}I dont have a test program at all. The program is supposed to prompt for user input of numbers. (it does) Take the input and end at input of -999 (it does). Then it asks user where it wants to split list (it does). When I enter a number it does nothing after that. I am going to post updated code and see if that helps along with all the classes. Thanks!
This is the class to prompt:
import java.util.*;
public class Ch16_ProgEx6
static Scanner console = new Scanner(System.in);
public static void main(String[] args)
UnorderedLinkedList<Integer> list
= new UnorderedLinkedList<Integer>();
UnorderedLinkedList<Integer> subList =
new UnorderedLinkedList<Integer>();
Integer num;
System.out.println("Enter integers ending with -999.");
num = console.nextInt();
while (num != -999)
list.insertLast(num);
num = console.nextInt();
System.out.println();
System.out.println("list: ");
list.print();
System.out.println();
System.out.println("Length of list: " + list.length());
System.out.print("Enter the number at which to split list: ");
num = console.nextInt();
list.splitAt(subList, num);
System.out.println("Lists after splitting list");
System.out.print("list: ");
list.print();
System.out.println();
System.out.println("Length of list: " + list.length());
System.out.print("sublist: ");
subList.print();
System.out.println();
System.out.println("Length of sublist: " + subList.length());
}This is the ADT:
public interface LinkedListADT<T> extends Cloneable
public Object clone();
//Returns a copy of objects data in store.
//This method clones only the references stored in
//each node of the list. The objects that the
//list nodes point to are not cloned.
public boolean isEmptyList();
//Method to determine whether the list is empty.
//Postcondition: Returns true if the list is empty;
// false otherwise.
public void initializeList();
//Method to initialize the list to an empty state.
//Postcondition: The list is initialized to an empty
// state.
public void print();
//Method to output the data contained in each node.
public int length();
//Method to return the number of nodes in the list.
//Postcondition: The number of nodes in the list is
// returned.
public T front();
//Method to return a reference of the object containing
//the data of the first node of the list.
//Precondition: The list must exist and must not be empty.
//Postcondition: The reference of the object that
// contains the info of the first node
// is returned.
public T back();
//Method to return a reference of object containing
//the data of the last node of the list.
//Precondition: The list must exist and must not be empty.
//Postcondition: The reference of the object that
// contains the info of the last node
// is returned.
public boolean search(T searchItem);
//Method to determine whether searchItem is in the list.
//Postcondition: Returns true if searchItem is found
// in the list; false otherwise.
public void insertFirst(T newItem);
//Method to insert newItem in the list.
//Postcondition: newItem is inserted at the
// beginning of the list.
public void insertLast(T newItem);
//Method to insert newItem at the end of the list.
//Postcondition: newItem is inserted at the end
// of the list.
public void deleteNode(T deleteItem);
//Method to delete deleteItem from the list.
//Postcondition: If found, the node containing
// deleteItem is deleted from the
// list.
public void splitAt(LinkedListClass<T> secondList, T item);
}This is the linked list class:
import java.util.NoSuchElementException;
public abstract class LinkedListClass<T> implements LinkedListADT<T>
protected class LinkedListNode<T> implements Cloneable
public T info;
public LinkedListNode<T> link;
//Default constructor
//Postcondition: info = null; link = null;
public LinkedListNode()
info = null;
link = null;
//Constructor with parameters
//This method sets info pointing to the object to
//which elem points to and link is set to point to
//the object to which ptr points to.
//Postcondition: info = elem; link = ptr;
public LinkedListNode(T elem, LinkedListNode<T> ptr)
info = elem;
link = ptr;
//Returns a copy of objects data in store.
//This method clones only the references stored in
//the node. The objects that the nodes point to
//are not cloned.
public Object clone()
LinkedListNode<T> copy = null;
try
copy = (LinkedListNode<T>) super.clone();
catch (CloneNotSupportedException e)
return null;
return copy;
//Method to return the info as a string.
//Postcondition: info as a String object is
// returned.
public String toString()
return info.toString();
} //end class LinkedListNode
public class LinkedListIterator<T>
protected LinkedListNode<T> current; //variable to
//point to the
//current node in
//list
protected LinkedListNode<T> previous; //variable to
//point to the
//node before the
//current node
//Default constructor
//Sets current to point to the first node in the
//list and sets previous to null.
//Postcondition: current = first; previous = null;
public LinkedListIterator()
current = (LinkedListNode<T>) first;
previous = null;
//Method to reset the iterator to the first node
//in the list.
//Postcondition: current = first; previous = null;
public void reset()
current = (LinkedListNode<T>) first;
previous = null;
//Method to return a reference of the info of the
//current node in the list and to advance iterator
//to the next node.
//Postcondition: previous = current;
// current = current.link;
// A refrence of the current node
// is returned.
public T next()
if (!hasNext())
throw new NoSuchElementException();
LinkedListNode<T> temp = current;
previous = current;
current = current.link;
return temp.info;
//Method to determine whether there is a next
//element in the list.
//Postcondition: Returns true if there is a next
// node in the list; otherwise
// returns false.
public boolean hasNext()
return (current != null);
//Method to remove the node currently pointed to
//by the iterator.
//Postcondition: If iterator is not null, then the
// node that the iterator points to
// is removed. Otherwise the method
// throws NoSuchElementException.
public void remove()
if (current == null)
throw new NoSuchElementException();
if (current == first)
first = first.link;
current = (LinkedListNode<T>) first;
previous = null;
if (first == null)
last = null;
else
previous.link = current.link;
if (current == last)
last = first;
while (last.link != null)
last = last.link;
current = current.link;
count--;
//Method to return the info as a string.
//Postcondition: info as a String object is returned.
public String toString()
return current.info.toString();
} //end class LinkedListIterator
//Instance variables of the class LinkedListClass
protected LinkedListNode<T> first; //variable to store the
//address of the first
//node of the list
protected LinkedListNode<T> last; //variable to store the
//address of the last
//node of the list
protected int count; //variable to store the number of
//nodes in the list
//Default constructor
//Initializes the list to an empty state.
//Postcondition: first = null, last = null,
// count = 0
public LinkedListClass()
first = null;
last = null;
count = 0;
//Method to determine whether the list is empty.
//Postcondition: Returns true if the list is empty;
// false otherwise.
public boolean isEmptyList()
return (first == null);
//Method to initialize the list to an empty state.
//Postcondition: first = null, last = null,
// count = 0
public void initializeList()
first = null;
last = null;
count = 0;
//Method to output the data contained in each node.
public void print()
LinkedListNode<T> current; //variable to traverse
//the list
current = first; //set current so that it points to
//the first node
while (current != null) //while more data to print
System.out.print(current.info + " ");
current = current.link;
}//end print
//Method to return the number of nodes in the list.
//Postcondition: The value of count is returned.
public int length()
return count;
//Method to return a reference of the object containing
//the data of the first node of the list.
//Precondition: The list must exist and must not be empty.
//Postcondition: The reference of the object that
// contains the info of the first node
// is returned.
public T front()
return first.info;
//Method to return a reference of object containing
//the data of the last node of the list.
//Precondition: The list must exist and must not be empty.
//Postcondition: The reference of the object that
// contains the info of the last node
// is returned.
public T back()
return last.info;
//Returns a copy of objects data in store.
//This method clones only the references stored in
//each node of the list. The objects that the
//list nodes point to are not cloned.
public Object clone()
LinkedListClass<T> copy = null;
try
copy = (LinkedListClass<T>) super.clone();
catch (CloneNotSupportedException e)
return null;
//If the list is not empty clone each node of
//the list.
if (first != null)
//Clone the first node
copy.first = (LinkedListNode<T>) first.clone();
copy.last = copy.first;
LinkedListNode<T> current;
if (first != null)
current = first.link;
else
current = null;
//Clone the remaining nodes of the list
while (current != null)
copy.last.link =
(LinkedListNode<T>) current.clone();
copy.last = copy.last.link;
current = current.link;
return copy;
//Method to return an iterator of the list.
//Postcondition: An iterator is instantiated and
// returned.
public LinkedListIterator<T> iterator()
return new LinkedListIterator<T>();
//Method to determine whether searchItem is in
//the list.
//Postcondition: Returns true if searchItem is found
// in the list; false otherwise.
public abstract boolean search(T searchItem);
//Method to insert newItem in the list.
//Postcondition: first points to the new list
// and newItem is inserted at the
// beginning of the list. Also,
// last points to the last node and
// count is incremented by 1.
public abstract void insertFirst(T newItem);
//Method to insert newItem at the end of the list.
//Postcondition: first points to the new list and
// newItem is inserted at the end
// of the list. Also, last points to
// the last node and
// count is incremented by 1.
public abstract void insertLast(T newItem);
//Method to delete deleteItem from the list.
//Postcondition: If found, the node containing
// deleteItem is deleted from the
// list. Also, first points to the first
// node, last points to the last
// node of the updated list, and count
// is decremented by 1.
public abstract void deleteNode(T deleteItem);
public abstract void splitAt(LinkedListClass<T> secondList, T item);
}And this is the UnorderedLinked Class with the very last method the one being Im stuck on. The SplitAt Method.
public class UnorderedLinkedList<T> extends LinkedListClass<T>
//Default constructor
public UnorderedLinkedList()
super();
//Method to determine whether searchItem is in
//the list.
//Postcondition: Returns true if searchItem is found
// in the list; false otherwise.
public boolean search(T searchItem)
LinkedListNode<T> current; //variable to traverse
//the list
boolean found;
current = first; //set current to point to the first
//node in the list
found = false; //set found to false
while (current != null && !found) //search the list
if (current.info.equals(searchItem)) //item is found
found = true;
else
current = current.link; //make current point to
//the next node
return found;
//Method to insert newItem in the list.
//Postcondition: first points to the new list
// and newItem is inserted at the
// beginning of the list. Also,
// last points to the last node and
// count is incremented by 1.
public void insertFirst(T newItem)
LinkedListNode<T> newNode; //variable to create the
//new node
newNode =
new LinkedListNode<T>(newItem, first); //create and
//insert newNode before
//first
first = newNode; //make first point to the
//actual first node
if (last == null) //if the list was empty, newNode is
//also the last node in the list
last = newNode;
count++; //increment count
//Method to insert newItem at the end of the list.
//Postcondition: first points to the new list and
// newItem is inserted at the end
// of the list. Also, last points to
// the last node and
// count is incremented by 1.
public void insertLast(T newItem)
LinkedListNode newNode; //variable to create the
//new node
newNode =
new LinkedListNode(newItem, null); //create newNode
if (first == null) //if the list is empty, newNode is
//both the first and last node
first = newNode;
last = newNode;
else //if the list is not empty, insert
//newNode after last
last.link = newNode; //insert newNode after last
last = newNode; //set last to point to the
//actual last node
count++;
}//end insertLast
//Method to delete deleteItem from the list.
//Postcondition: If found, the node containing
// deleteItem is deleted from the
// list. Also, first points to the first
// node, last points to the last
// node of the updated list, and count
// is decremented by 1.
public void deleteNode(T deleteItem)
LinkedListNode<T> current; //variable to traverse
//the list
LinkedListNode<T> trailCurrent; //variable just
//before current
boolean found;
if ( first == null) //Case 1; the list is empty
System.err.println("Cannot delete from an empty "
+ "list.");
else
if (first.info.equals(deleteItem)) //Case 2
first = first.link;
if (first == null) //the list had only one node
last = null;
count--;
else //search the list for the given info
found = false;
trailCurrent = first; //set trailCurrent to
//point to the first node
current = first.link; //set current to point to
//the second node
while (current != null && !found)
if (current.info.equals(deleteItem))
found = true;
else
trailCurrent = current;
current = current.link;
}//end while
if (found) //Case 3; if found, delete the node
count--;
trailCurrent.link = current.link;
if (last == current) //node to be deleted
//was the last node
last = trailCurrent; //update the value
//of last
else
System.out.println("Item to be deleted is "
+ "not in the list.");
}//end else
}//end else
}//end deleteNode
public void splitAt(LinkedListClass<T> secondList, T item)
LinkedListNode<T> current;
LinkedListNode<T> trailCurrent;
int i;
boolean found;
if (first==null)
System.out.println("Empty.");
first=null;
last=null;
count--;
count=0;
else
current=first;
found=false;
i=1;
while(current !=null &&!found)
if(current.info.equals(item))
found= true;
else
trailCurrent=first;
current=first;
i++;
if(found)
if(first==current)
first.link=first;
last.link=last;
count--;
count=0;
else
first.link=current;
last.link=last;
last=null;
count = count- i+1;
count = i-1;
} else {
System.out.println("Item to be split at is "
+ "not in the list.");
first=null;
last=null;
count=0;
Any help or just advice would be fine. Im not the best at Java, better at VB. Am completely stumped! Thanks so much!
Maybe you are looking for
-
Hi All, According to the requirement I have to make the CURR type field as the key field in one of the table. But dureing activation it's throwing the below warning : Key field <Field name> has num. type CURR: Buffering not possible, Transp
-
Purchasing and Advance Pricing
I need the following 1. Define a List Price for Supplier X item a (price 10) 2. Define a List Price for Supplier Y item a (price 20) Is there a some way that PO when I put the item in a Purchase Order detected the best price for the item? In other wa
-
I have exactly the same problem as PhotoshopBill: cannot install CS5 updates before closing Bridge.exe, even though it clearly is not open. I am still trying to install Photoshop update 12.0.3, and there already is 12.0.4 available. The Adobe Support
-
I have a problem related purchase
-
External services confirmation- ML81N vs. IW42??
Hello everyone, I have a question around confirmation of external services, addressing to those who are savvy with external services config side.. First of all- Does accepted service entry sheet represent itself a confirmation? Or do we need also con