Please Hilp me ( about linked list)
i am an university student
i was write a proram by ( arrays)
thes program about Employees ( Add , Searsh , displly , delete )
it is 6 class
1 = Employee.java
2 = Boss.java
3 = CommissionWorker.java
4 = HourlyWorker.java
5 = PieceWorker.java
6 = StartProgram.java
i wona now changing the program from (Arrays) to (linked list)
this is the cood
The last 1
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class StartProgram extends JFrame
// The Components For Frame 1
private JLabel Label_Number_Of_Employee ;
private JTextField Text_Number_Of_Employee ;
private JButton Button_New, Button_Display, Button_Search, Button_UpData, Button_Delete;
private JButton Button_Exit, Button_RE;
private JPanel Panel_1_North, Panel_1_West, Panel_1_South, Panel_1_Center;
// The Components For Frame 2
private JLabel Label_Name, Label_Adress, Label_Gread, Label_ID, Label_Salary , Label_Commiss, Label_Quant, Label_Hour, Label_Wage, Label_Pice, Label_Total_Mony, Label_NumberID_FOR_Searsh;
private JTextField TextField_Total_mony, TextField_Name, TextField_Adress, TextField_Greade, TextField_ID, TextField_Salary , TextField_Commiss, TextField_Quant, TextField_Hour, TextField_Wage, TextField_Pice, TextField_NumberID_FOR_Searsh;
private JButton Button_Clear, Button_OK2, Button_Cancel, Button_Next, Button_Prev, Button_Searsh, Button_Save, Button_Delet, Button_Create;
private JRadioButton rad_Boss, rad_HourlyWorker, rad_PiceWorker, rad_CommissWorker;
private ButtonGroup radGroup;
private JPanel Panel_2_Center, Panel_2_South, Panel_2_North;
// The Container For Frame 1
Container cont;
// The Container For Frame 2
Container cont2;
// The Layouts For Frame 1 & 2
private FlowLayout layout;
private GridLayout glayout;
// private class Show_Frame2 extends JFrame
int ID_Conter_Number[] = new int[1];
Show_Frame2 Frame_Display;
Show_Frame2 Frame_Delete;
Show_Frame2 Frame_UpData;
Show_Frame2 Frame_Search;
// VARIABLES
int Text_Number_TO_int = 0;
int Countr_Index_Of_ArrayEmp = 0;
int Number_Chose_Acion;
int Conter_next = -1;
int Number_Stop_Create = 0;
int NumberID_FOR_Searsh = 0 ;
int Nu_S_S_D_F_T_F_T_T_A; // use in Set_Save_Data_From_Text_Field_To_The_Arayy();
int Number_Set_Kind_Employee; // use in Set_Save_Data_From_Text_Field_To_The_Arayy();
int Nu_S_K_E_B_R_S; // use in Set_Kind_Employee_By_radBotton_Selected()
int Nu_S_D_I_F_T_S_B_S_O_D; // use in Set_Data_in_Folds_To_Show_By_Searsh_Or_Disply()
// use in Set_Save_Data_From_Text_Field_To_The_Arayy()
int ID_set_Save_Data;
int Greade_set_Save_Data;
String Adress_set_Save_Data;
String Name_set_Save_Data;
double Salary_set_Save_Data;
int Quant_set_Save_Data;
int Hour_set_Save_Data;
int Pice_set_Save_Data;
double Wage_set_Save_Data;
double Commiss_set_Save_Data;
double Total_Mony;
// For updata
int ID_updata;
int Greade_updata;
String Adress_updata;
String Name_updata;
double Salary_updata;
int Quant_updata;
int Hour_updata;
int Pice_updata;
double Wage_updata;
double Commiss_updata;
double Total_Mony_updata;
// Arayy(s) To Keep Elements Data Of Employee
String ArayyName[];
String ArayyAdress[];
int ArayyGreade[];
int ArayyID[];
double ArayySalary[];
double ArayyCommiss[];
int ArayyQuant[];
int ArayyHour[];
double ArayyWage[];
int ArayyPice[];
int ArayyKind_Emp[];
// Arayy(s)2 To Keep A Copy Of Elements Data Of Employee
// Use in Delete Action
String ArayyName_Copy[];
String ArayyAdress_Copy[];
int ArayyGreade_Copy[];
int ArayyID_Copy[];
double ArayySalary_Copy[];
double ArayyCommiss_Copy[];
int ArayyQuant_Copy[];
int ArayyHour_Copy[];
double ArayyWage_Copy[];
int ArayyPice_Copy[];
int ArayyKind_Emp_Copy[];
// CONSRUCTOR of StartProgram class
// Open form1
public StartProgram()
super("Start To Employee System Control");
cont = getContentPane();
Panel_1_North = new JPanel(); Panel_1_North.setLayout(new GridLayout(3,0,0,0));
Panel_1_Center = new JPanel(); Panel_1_Center.setLayout(new GridLayout(6,0,0,0));
Panel_1_South = new JPanel(); Panel_1_South.setLayout(new GridLayout(1,0,0,0));
Label_Number_Of_Employee = new JLabel("Enter The Number Of Employees Then Press (ENTER) In Your KeyBoard ! ");
Text_Number_Of_Employee = new JTextField(10);
// 1- Display Button Choice To Employee System Control in form1
// 2- set Buttons Edit = false
Button_New = new JButton("Create a new an Employee(s) "); Button_New.setVisible(false);
Button_Display = new JButton("Display an Employee(s) "); Button_Display.setVisible(false);
Button_Search = new JButton("Search for an Employee(s) "); Button_Search.setVisible(false);
Button_UpData = new JButton("UpData for an Employee(s) "); Button_UpData.setVisible(false);
Button_Delete = new JButton("Delete an Employee(s) "); Button_Delete.setVisible(false);
// 1- Display Button ( EXIT & START AGEN ) in form1
// 2- set Buttons Edit = false
Button_Exit = new JButton("EXIT"); Button_Exit.setEnabled(false);
Button_RE = new JButton("START AGEN"); Button_RE.setEnabled(false);
// an object from the private class ActionHandler
ActionHandler handler = new ActionHandler();
Button_New.addActionListener(handler);
Button_Display.addActionListener(handler);
Button_Search.addActionListener(handler);
Button_UpData.addActionListener(handler);
Button_Delete.addActionListener(handler);
Button_Exit.addActionListener(handler);
Button_RE.addActionListener(handler);
Text_Number_Of_Employee.addActionListener(handler);
// Add all objects in form1
Panel_1_North.add(Label_Number_Of_Employee);
Panel_1_North.add(Text_Number_Of_Employee);
Panel_1_Center.add(Button_New);
Panel_1_Center.add(Button_Display);
Panel_1_Center.add(Button_Search);
Panel_1_Center.add(Button_UpData);
Panel_1_Center.add(Button_Delete);
Panel_1_South.add(Button_Exit);
Panel_1_South.add(Button_RE);
cont.add(Panel_1_North , BorderLayout.NORTH);
cont.add(Panel_1_Center , BorderLayout.CENTER);
cont.add(Panel_1_South , BorderLayout.SOUTH);
// setting of form1
setSize(450,350);
setVisible(true);
setResizable(false);
} // END public StartProgram()
private class ActionHandler implements ActionListener
public void actionPerformed(ActionEvent EEEE)
// ================================================
// ================================================
// if user Put A Number Then He clock Enter
if(EEEE.getSource() == Text_Number_Of_Employee)
Set_Enter_Number_Of_Employee_Start();
// ================================================
// ================================================
// Or if user clock Button Exit
else if(EEEE.getSource() == Button_Exit)
System.gc();
System.exit(0);
// ================================================
// ================================================
// if user clock Button RE START
if(EEEE.getSource() == Button_RE)
Set_Program_Start_Agen();
// ================================================
// ================================================
// if user clock Button Create a new Employee
if(EEEE.getSource() == Button_New)
Number_Chose_Acion = 1;
Show_Frame2 CCCC = new Show_Frame2();
// ================================================
// ================================================
// if user clock Button Display The Employee
if(EEEE.getSource() == Button_Display)
Number_Chose_Acion = 2;
Show_Frame2 CCCC = new Show_Frame2();
// ================================================
// ================================================
// if user clock Button Search The Employee
if(EEEE.getSource() == Button_Search)
Number_Chose_Acion = 3;
Show_Frame2 CCCC = new Show_Frame2();
// ================================================
// ================================================
// if user clock Button UpData The Employee
if(EEEE.getSource() == Button_UpData)
Number_Chose_Acion = 4;
Show_Frame2 CCCC = new Show_Frame2();
// ================================================
// ================================================
// if user clock Button Delete
if(EEEE.getSource() == Button_Delete)
Number_Chose_Acion = 5;
Show_Frame2 CCCC = new Show_Frame2();
} // END public void actionPerformed(ActionEvent e)
} // END private class ActionHandler implements ActionListener
public void Set_Enter_Number_Of_Employee_Start()
try
Text_Number_TO_int = Integer.parseInt(Text_Number_Of_Employee.getText());
if(Text_Number_TO_int <= 0)
Text_Number_Of_Employee.setText("ERROR !! Please Enter a Number More Than 0");
else
Set_Create_Lingth_Of_Arayy_By_Number_That_Entered();
catch(NumberFormatException nfe)
Text_Number_Of_Employee.setText("ERROR !! Please Enter a Number");
public void Set_Create_Lingth_Of_Arayy_By_Number_That_Entered()
ID_Conter_Number = new int[Text_Number_TO_int];
Text_Number_Of_Employee.setEditable(false);
Button_New.setVisible(true);
Button_Display.setVisible(true);
Button_Search.setVisible(true);
Button_UpData.setVisible(true);
Button_Delete.setVisible(true);
Button_Exit.setEnabled(true);
Button_RE.setEnabled(true);
ArayyName = new String[Text_Number_TO_int];
ArayyAdress = new String[Text_Number_TO_int];
ArayyGreade = new int[Text_Number_TO_int];
ArayyID = new int[Text_Number_TO_int];
ArayySalary = new double[Text_Number_TO_int];
ArayyCommiss = new double[Text_Number_TO_int];
ArayyQuant = new int[Text_Number_TO_int];
ArayyHour = new int[Text_Number_TO_int];
ArayyWage = new double[Text_Number_TO_int];
ArayyPice = new int[Text_Number_TO_int];
ArayyKind_Emp = new int[Text_Number_TO_int];
public void Set_Program_Start_Agen()
Text_Number_Of_Employee.setEditable(true);
Text_Number_Of_Employee.setText("");
Countr_Index_Of_ArrayEmp = 0;
Conter_next = -1;
Text_Number_TO_int = 0;
Countr_Index_Of_ArrayEmp = 0;
Conter_next = -1;
Nu_S_S_D_F_T_F_T_T_A = 0;
Number_Set_Kind_Employee = 0;
Number_Stop_Create = 0;
ArayyName = null ;
ArayyAdress = null ;
ArayyGreade = null ;
ArayyID = null ;
ArayySalary = null ;
ArayyCommiss = null ;
ArayyQuant = null ;
ArayyHour = null ;
ArayyWage = null ;
ArayyPice = null ;
ArayyKind_Emp = null ;
ArayyName_Copy = null ;
ArayyAdress_Copy = null ;
ArayyGreade_Copy = null ;
ArayyID_Copy = null ;
ArayySalary_Copy = null ;
ArayyCommiss_Copy = null ;
ArayyQuant_Copy = null ;
ArayyHour_Copy = null ;
ArayyWage_Copy = null ;
ArayyPice_Copy = null ;
ArayyKind_Emp_Copy = null ;
ID_set_Save_Data = 0;
Greade_set_Save_Data = 0;
Adress_set_Save_Data = null;
Name_set_Save_Data = null;
Salary_set_Save_Data = 0.00;
Quant_set_Save_Data = 0;
Hour_set_Save_Data = 0;
Pice_set_Save_Data = 0;
Wage_set_Save_Data = 0.00;
Commiss_set_Save_Data = 0.00;
// Whin User Click Any rad Button
private class RadHandler implements ItemListener
public void itemStateChanged(ItemEvent i)
Set_All_Text_Field_To_Defolt_Text();
TextField_Name.setEditable(true);
TextField_Adress.setEditable(true);
TextField_Greade.setEditable(true);
if(i.getSource() == rad_Boss)
TextField_Salary.setEditable(true);
TextField_Wage.setEditable(false);
TextField_Commiss.setEditable(false);
TextField_Quant.setEditable(false);
TextField_Hour.setEditable(false);
TextField_Pice.setEditable(false);
else if(i.getSource() == rad_HourlyWorker)
TextField_Salary.setEditable(false);
TextField_Wage.setEditable(true);
TextField_Hour.setEditable(true);
TextField_Commiss.setEditable(false);
TextField_Quant.setEditable(false);
TextField_Pice.setEditable(false);
else if(i.getSource() == rad_PiceWorker)
TextField_Salary.setEditable(false);
TextField_Wage.setEditable(true);
TextField_Hour.setEditable(false);
TextField_Quant.setEditable(false);
TextField_Commiss.setEditable(false);
TextField_Pice.setEditable(true);
else if(i.getSource() == rad_CommissWorker)
TextField_Salary.setEditable(true);
TextField_Wage.setEditable(false);
TextField_Hour.setEditable(false);
TextField_Quant.setEditable(false);
TextField_Commiss.setEditable(true);
TextField_Pice.setEditable(true);
private class Show_Frame2 extends JFrame
public Show_Frame2()
super("Control Panal Of Employee's Data");
cont2 = getContentPane();
Panel_2_Center = new JPanel();
Panel_2_Center.setLayout(new GridLayout(11,2,5,5));
Panel_2_South = new JPanel();
Panel_2_South.setLayout(new GridLayout(2,5,5,5));
Panel_2_North = new JPanel();
Panel_2_North.setLayout(new GridLayout(2,1,5,5));
Label_NumberID_FOR_Searsh = new JLabel("Employee's ID :", SwingConstants.RIGHT);
Label_NumberID_FOR_Searsh.setVisible(false);
TextField_NumberID_FOR_Searsh = new JTextField(5);
TextField_NumberID_FOR_Searsh.setVisible(false);
TextField_NumberID_FOR_Searsh.setEditable(false);
Label_Name = new JLabel("Name : " , SwingConstants.RIGHT);
Label_Adress = new JLabel("Address : " , SwingConstants.RIGHT);
Label_Gread = new JLabel("Greade : " , SwingConstants.RIGHT);
Label_ID = new JLabel("ID : " , SwingConstants.RIGHT);
Label_Salary = new JLabel("Salary : " , SwingConstants.RIGHT);
Label_Commiss = new JLabel("Commiss : " , SwingConstants.RIGHT);
Label_Quant = new JLabel("Quant : " , SwingConstants.RIGHT);
Label_Hour = new JLabel("Hours : " , SwingConstants.RIGHT);
Label_Wage = new JLabel("Wage : " , SwingConstants.RIGHT);
Label_Pice = new JLabel("Pice : " , SwingConstants.RIGHT);
Label_Total_Mony = new JLabel("Total_Money : " , SwingConstants.RIGHT);
TextField_Name = new JTextField(45);
TextField_Adress = new JTextField(45);
TextField_Greade = new JTextField(2);
TextField_ID = new JTextField(4);
TextField_Salary = new JTextField(10);
TextField_Commiss = new JTextField(10);
TextField_Quant = new JTextField(10);
TextField_Hour = new JTextField(10);
TextField_Wage = new JTextField(10);
TextField_Pice = new JTextField(10);
TextField_Total_mony = new JTextField(10); TextField_Total_mony.setEditable(false);
rad_Boss = new JRadioButton("Boss" , false);
rad_HourlyWorker = new JRadioButton("Hourly" , false);
rad_PiceWorker = new JRadioButton("Pice" , false);
rad_CommissWorker = new JRadioButton("Commiss" , false);
radGroup = new ButtonGroup();
radGroup.add(rad_Boss);
radGroup.add(rad_HourlyWorker);
radGroup.add(rad_PiceWorker);
radGroup.add(rad_CommissWorker);
//handler is object of private class RadHandler
RadHandler rHandler = new RadHandler();
rad_Boss.addItemListener(rHandler);
rad_HourlyWorker.addItemListener(rHandler);
rad_PiceWorker.addItemListener(rHandler);
rad_CommissWorker.addItemListener(rHandler);
Button_Save = new JButton("Save"); Button_Save.setVisible(false);
Button_Delet = new JButton("Delete"); Button_Delet.setVisible(false);
Button_Searsh = new JButton("Search"); Button_Searsh.setVisible(false);
Button_Next = new JButton("next");
Button_Prev = new JButton("Prev");
Button_Clear = new JButton("Clear");
Button_OK2 = new JButton("OK"); Button_OK2.setEnabled(false);
Button_Cancel = new JButton("Cancel/Menu");
Button_Create = new JButton("Create");
// ================================================
// ================================================
// of usrt click Button Clear
Button_Clear.addActionListener
new ActionListener()
public void actionPerformed(ActionEvent e)
Set_Part_Of_Text_Field_Clear_of_Text();
// ================================================
// ================================================
// of usrt click Button Cancel / Menu
Button_Cancel.addActionListener
new ActionListener()
public void actionPerformed(ActionEvent e)
setVisible(false);
// ================================================
// ================================================
// 111111111111111111111111111111111111111111111111//
// (Create new Employee)
if (Number_Chose_Acion == 1)
if (Number_Stop_Create >= Text_Number_TO_int)
JOptionPane.showMessageDialog(cont2, "You Can not add more Employees " , "Createing Will stop",JOptionPane.INFORMATION_MESSAGE);
else
set_Show_Create_employees_Form();
// ================================================
// ================================================
// 222222222222222222222222222222222222222222222222//
// ( Display Employee)
else if (Number_Chose_Acion == 2)
if (ArayyName[0] == null)
JOptionPane.showMessageDialog(cont2,"Ther are No Employees to Display", "Exception Display",JOptionPane.ERROR_MESSAGE);
else
set_Show_Display_employees_Form();
// ================================================
// ================================================
// 333333333333333333333333333333333333333333333333//
// ( Search Employee)
else if (Number_Chose_Acion == 3)
try
if (ArayyName[0] == null)
JOptionPane.showMessageDialog(cont2,"Ther are No Employees to Search", "Exception Search",JOptionPane.ERROR_MESSAGE);
else
set_Show_Search_employees_Form();
catch (Exception ex)
JOptionPane.showMessageDialog(cont2,ex, "Exception",JOptionPane.ERROR_MESSAGE);
// ================================================
// ================================================
// 444444444444444444444444444444444444444444444444//
// ( UpData Employee)
else if (Number_Chose_Acion == 4)
try
if (ArayyName[0] == null)
JOptionPane.showMessageDialog(cont2,"Ther are No Employees to UpData", "Exception UpData",JOptionPane.ERROR_MESSAGE);
else
set_Show_UpData_employees_Form();
catch (Exception ex)
JOptionPane.showMessageDialog(cont2,ex, "Exception",JOptionPane.ERROR_MESSAGE);
// ================================================
// ================================================
// 555555555555555555555555555555555555555555555555//
// ( Delete Action )
else if (Number_Chose_Acion == 5)
try
if (ArayyName[0] == null)
JOptionPane.showMessageDialog(cont2,"Ther are No Employees to Delete", "Exception Delete",JOptionPane.ERROR_MESSAGE);
else
set_Show_Delete_employees_Form();
catch (Exception ex)
JOptionPane.showMessageDialog(cont2,ex, "Exception",JOptionPane.ERROR_MESSAGE);
// ================================================
// ================================================
} // END public Show_Frame2()
// 11111111111111111111111111111111111111111
public void set_Show_Create_employees_Form()
set_Container_Of_Form2();
setTitle("Create employees");
setResizable(false);
setSize(600,500);
setVisible(true);
Set_TextField_Editable_IS_FALSE();
Conter_next = 0;
// whin Fram Create new Employee loading
Button_Next.setEnabled(false);
Button_Prev.setEnabled(false);
// of usrt click Button Create
Button_Create.addActionListener
new ActionListener()
public void actionPerformed(ActionEvent e)
// Kind of Employee that will ad is boss
if(rad_Boss.isSelected() == true)
try
int Greade_N = Integer.parseInt(TextField_Greade.getText());
if ( (Greade_N > 99) || (Greade_N < 1) )
JOptionPane.showMessageDialog(cont2," Please\nEnter Number in (Greade) Between 1 To 99", "ERROR NUMBER",JOptionPane.ERROR_MESSAGE);
else
Nu_S_S_D_F_T_F_T_T_A = Countr_Index_Of_ArrayEmp;
Number_Set_Kind_Employee = 1; // = Boss
Set_Save_Data_From_Text_Field_To_The_Arayy();
Set_All_Text_Field_To_Defolt_Text();
JOptionPane.showMessageDialog(cont2,Name_set_Save_Data + "\nwas Created As Boss", "Create",JOptionPane.INFORMATION_MESSAGE);
Countr_Index_Of_ArrayEmp ++;
Number_Stop_Create ++;
catch(Exception ex)
JOptionPane.showMessageDialog(cont2,"Please Enter Correct Data\n"+ex, "Exception",JOptionPane.ERROR_MESSAGE);
// Kind of Employee that will ad is rad_HourlyWorker
if(rad_HourlyWorker.isSelected() == true)
try
int Greade_N = Integer.parseInt(TextField_Greade.getText());
if ( (Greade_N > 99) || (Greade_N < 1) )
JOptionPane.showMessageDialog(cont2," Please\nEnter Number in (Greade) Between 1 To 99", "ERROR NUMBER",JOptionPane.ERROR_MESSAGE);
else
Nu_S_S_D_F_T_F_T_T_A = Countr_Index_Of_ArrayEmp;
Number_Set_Kind_Employee = 2; // = HourlyWorker
Set_Save_Data_From_Text_Field_To_The_Arayy();
Set_All_Text_Field_To_Defolt_Text();
JOptionPane.showMessageDialog(cont2,Name_set_Save_Data + "\nwas Created As HourlyWorker", "Create",JOptionPane.INFORMATION_MESSAGE);
Countr_Index_Of_ArrayEmp ++;
Number_Stop_Create ++;
catch(Exception ex)
JOptionPane.showMessageDialog(cont2,ex, "Exception",JOptionPane.ERROR_MESSAGE);
// Kind of Employee that will ad is rad_PiceWorker
if(rad_PiceWorker.isSelected() == true)
try
int Greade_N = Integer.parseInt(TextField_Greade.getText());
if ( (Greade_N > 99) || (Greade_N < 1) )
JOptionPane.showMessageDialog(cont2," Please\nEnter Number in (Greade) Between 1 To 99", "ERROR NUMBER",JOptionPane.ERROR_MESSAGE);
else
Nu_S_S_D_F_T_F_T_T_A = Countr_Index_Of_ArrayEmp;
Number_Set_Kind_Employee = 3; // = PiceWorker
Set_Save_Data_From_Text_Field_To_The_Arayy();
Set_All_Text_Field_To_Defolt_Text();
JOptionPane.showMessageDialog(cont2,Name_set_Save_Data + "\nwas Created As PiceWorker", "Create",JOptionPane.INFORMATION_MESSAGE);
Countr_Index_Of_ArrayEmp ++;
Number_Stop_Create ++;
Similar Messages
-
Quick Question about linked lists
If I have a linked list can i save it to a file directly with the Serializable interface or would I have to iterate through each element and write each element to the file?
yeah, it seems as though I can
However, I am having a problem reading it back. I guess I don't know how to initialize the values in the list, as it doens't recognize anything until I add an item to it and it adds this item to the front, then any other items after that it will add to the back, when i want this first addition to be in the back as well.
when I initialize the class i call
list.add(loadList());
loadList()
public MyList loadList() {
try {
FileInputStream fis = new FileInputStream("data.dat");
ObjectInputStream in = new ObjectInputStream(fis);
list = (MyList)in.readObject();
in.close();
return list;
catch (Exception e) {
System.out.println(e);
return list;
}list.add()
public void add(int index, Object o)
if (index == 0) addFirst(o);
else if (index >= size) addLast(o);
else {
Node current = first;
for (int i = 1; i < index; i++)
current.prev = current;
current = current.next;
Node temp = current.next;
current.next = new Node(o);
current.prev = current;
(current.next).next = temp;
size++;
}any ideas? -
I'm doing an assignment on linked lists and I'm having trouble understanding the insert method. I'm using the one from the book and it works fine, but I don't quite understand it.
public void insert(Object o) {
Node n = new Node(o,current);
if (previous == null)
head = n;
else
previous.next = n;
current = n;
It's my understanding that current is the value that your currently at in the list. Previous is equal to the value before the current. So, previous.next is equal to current. This reasoning won't make the list progress with this code. Can someone tell me what I'm not understanding, or explain how this progresses?Thanks, that helps alot. Now, I have another question. I need to add and remove nodes from the list. I have it setup where the user can choose what node to delete. It compiles and runs fine, but when I try to delete a node, it doesn't delete it. Doing some troubleshooting, I found that it gets into the for loop, but doesn't do anything with the if/else statement. I put a printline in the if and else part, and it never printed out the statement in the if statement or in the else statement. Here's the code I'm using. getLentgh() is a method I wrote to return an integer value of how many nodes are in the list. I've also tried putting in a printline after the for loop, but still in the try, it didn't print it out.
else if(source == remove) {
String del = JOptionPane.showInputDialog("Enter an integer to remove.");
Node temp = new Node(del,current);
if(del != null){
try{
for(int c = 0; c < list.getLength(); c++){
if(temp.data == current.data){
list.remove();
c = list.getLength();
else{
list.advance();
}catch(NullPointerException e){
} -
Linked lists problem -- help needed
Hello again. I've got yet another problem in my C++ course that stems from my use of a Mac instead of Windows. I'm going to install Parallels so I can get Windows on my MacBook and install Visual Studio this week so that I don't have to deal with these discrepancies anymore, but in the meanwhile, I'm having a problem here that I don't know how to resolve. To be clear, I've spent a lot of time trying to work this out myself, so I'm not just throwing this up here to have you guys do the work for me -- I'm really stuck here, and am coming here as a last resort, so I'll be very, very appreciative for any help that anyone can offer.
In my C++ course, we are on a chapter about linked lists, and the professor has given us a template to make the linked lists work. It comes in three files (a header, a source file, and a main source file). I've made some adjustments -- the original files the professor provided brought up 36 errors and a handful of warnings, but I altered the #include directives and got it down to 2 errors. The problematic part of the code (the part that contains the two errors) is in one of the function definitions, print_list(), in the source file. That function definition is shown below, and I've marked the two statements that have the errors using comments that say exactly what the errors say in my Xcode window under those two statements. If you want to see the entire template, I've pasted the full code from all three files at the bottom of this post, but for now, here is the function definition (in the source file) that contains the part of the code with the errors:
void LinkedList::printlist( )
// good for only a few nodes in a list
if(isEmpty() == 1)
cout << "No nodes to display" << endl;
return;
for(CURSOR = FRONT_ptr; CURSOR; CURSOR = CURSOR-> link)
{ cout << setw(8) << CURSOR->name; } cout << endl; // error: 'setw' was not declared in this scope
for(CURSOR = FRONT_ptr; CURSOR; CURSOR = CURSOR-> link)
{ cout << setw(8) << CURSOR->test_grade; } cout << endl; // error: 'setw' was not declared in this scope
As you can see, the problem is with the two statements that contain the 'setw' function. Can anyone help me figure out how to get this template working and get by these two errors? I don't know enough about linked lists to know what I can and can't mess with here to get it working. The professor recommended that I try using 'printf' instead of 'cout' for those two statements, but I don't know how to achieve the same effect (how to do whatever 'setw' does) using 'printf'. Can anyone please help me get this template working? Thank you very, very much.
For reference, here is the full code from all three files that make up the template:
linkedlist.h (header file):
#ifndef LINKED_LINKED_H
#define LINKED_LINKED_H
struct NODE
string name;
int test_grade;
NODE * link;
class Linked_List
public:
Linked_List();
void insert(string n, int score);
void remove(string target);
void print_list();
private:
bool isEmpty();
NODE *FRONT_ptr, *REAR_ptr, *CURSOR, *INSERT, *PREVIOUS_ptr;
#endif
linkedlist.cpp (source file):
#include <iostream>
using namespace std;
#include "linkedlist.h"
LinkedList::LinkedList()
FRONT_ptr = NULL;
REAR_ptr = NULL;
PREVIOUS_ptr = NULL;
CURSOR = NULL;
void Linked_List::insert(string n, int score)
INSERT = new NODE;
if(isEmpty()) // first item in List
// collect information into INSERT NODE
INSERT-> name = n;
// must use strcpy to assign strings
INSERT -> test_grade = score;
INSERT -> link = NULL;
FRONT_ptr = INSERT;
REAR_ptr = INSERT;
else // else what?? When would this happen??
// collect information into INSERT NODE
INSERT-> name = n; // must use strcpy to assign strings
INSERT -> test_grade = score;
REAR_ptr -> link = INSERT;
INSERT -> link = NULL;
REAR_ptr = INSERT;
void LinkedList::printlist( )
// good for only a few nodes in a list
if(isEmpty() == 1)
cout << "No nodes to display" << endl;
return;
for(CURSOR = FRONT_ptr; CURSOR; CURSOR = CURSOR-> link)
{ cout << setw(8) << CURSOR->name; } cout << endl; // error: 'setw' was not declared in this scope
for(CURSOR = FRONT_ptr; CURSOR; CURSOR = CURSOR-> link)
{ cout << setw(8) << CURSOR->test_grade; } cout << endl; // error: 'setw' was not declared in this scope
void Linked_List::remove(string target)
// 3 possible places that NODES can be removed from in the Linked List
// FRONT
// MIDDLE
// REAR
// all 3 condition need to be covered and coded
// use Trasversing to find TARGET
PREVIOUS_ptr = NULL;
for(CURSOR = FRONT_ptr; CURSOR; CURSOR = CURSOR-> link)
if(CURSOR->name == target) // match
{ break; } // function will still continue, CURSOR will
// mark NODE to be removed
else
{ PREVIOUS_ptr = CURSOR; } // PREVIOUS marks what NODE CURSOR is marking
// JUST before CURSOR is about to move to the next NODE
if(CURSOR == NULL) // never found a match
{ return; }
else
// check each condition FRONT, REAR and MIDDLE
if(CURSOR == FRONT_ptr)
// TARGET node was the first in the list
FRONT_ptr = FRONT_ptr -> link; // moves FRONT_ptr up one node
delete CURSOR; // deletes and return NODE back to free memory!!!
return;
}// why no need for PREVIOUS??
else if (CURSOR == REAR_ptr) // TARGET node was the last in the list
{ // will need PREVIOUS for this one
PREVIOUS_ptr -> link = NULL; // since this node will become the last in the list
REAR_ptr = PREVIOUS_ptr; // = REAR_ptr; // moves REAR_ptr into correct position in list
delete CURSOR; // deletes and return NODE back to free memory!!!
return;
else // TARGET node was the middle of the list
{ // will need PREVIOUS also for this one
PREVIOUS_ptr -> link = CURSOR-> link; // moves PREV nodes' link to point where CURSOR nodes' points
delete CURSOR; // deletes and return NODE back to free memory!!!
return;
bool Linked_List::isEmpty()
if ((FRONT_ptr == NULL) && (REAR_ptr == NULL))
{ return true; }
else
{ return false;}
llmain.cpp (main source file):
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
#include "linkedlist.h"
int main()
Linked_List one;
one.insert("Angela", 261);
one.insert("Jack", 20);
one.insert("Peter", 120);
one.insert("Chris", 270);
one.print_list();
one.remove("Jack");
one.print_list();
one.remove("Angela");
one.print_list();
one.remove("Chris");
one.print_list();
return 0;setw is the equivalent of the field width value in printf. In your code, the printf version would look like:
printf("%8s", CURSOR->name.c_str());
I much prefer printf over any I/O formatting in C++. See the printf man page for more information. I recommend using Bwana: http://www.bruji.com/bwana/
I do think it is a good idea to verify your code on the platform it will be tested against. That means Visual Studio. However, you don't want to use Visual Studio. As you have found out, it gets people into too many bad habits. Linux is much the same way. Both development platforms are designed to build anything, whether or not it is syntactically correct. Both GNU and Microsoft have a long history of changing the language standards just to suit themselves.
I don't know what level you are in the class, but I have a few tips for you. I'll phrase them so that they answers are a good exercise for the student
* Look into const-correctness.
* You don't need to compare a bool to 1. You can just use bool. Plus, any integer or pointer type has an implicit cast to bool.
* Don't reuse your CURSOR pointer as a temporary index. Create a new pointer inside the for loop.
* In C++, a struct is the same thing as a class, with all of its members public by default. You can create constructors and member functions in a struct.
* Optimize your function arguments. Pass by const reference instead of by copy. You will need to use pass by copy at a later date, but don't worry about that now.
* Look into initializer lists.
* In C++ NULL and 0 are always the same.
* Return the result of an expression instead of true or false. Technically this isn't officially Return Value Optimization, but it is a good habit.
Of course, get it running first, then make it fancy. -
Help PLEASE with linked list. Inserting a string in the middle of
I'm trying to insert new strings to a linked list but it seem i cant never insert. the following code has the instructions. What i'm I not doing right? If i try to use the code, the new strings don't go through
please help someone
// This method should insert a new node containing the string newString immediately after the first
// occurrence of the string aString in the list. If aString is not in the list, the method should add a node
// containing newString to the tail of the list.
public void insertAfter(String newString, String aString)
StringLLNode newNode = new StringLLNode();
newNode.setData(newString);
//Check if HeadNode == aString
if (headNode.getData().equalsIgnoreCase(aString))
headNode = newNode;
//rest of the nodes
StringLLNode currNode = headNode;
while(currNode != null)
if (currNode.getData().equalsIgnoreCase(aString))
newNode.setNext(currNode);
//System.out.println("It went THROUGH");
currNode = currNode.getNext();
//Last Node
if (currNode != null)
newNode.setNext(headNode);
}I have to agree with flounder, go grab a pen and paper and logically work thru the code snippet you posted.
public void insertAfter(String newString, String aString)
StringLLNode newNode = new StringLLNode();
newNode.setData(newString);
//Check if HeadNode == aString
if (headNode.getData().equalsIgnoreCase(aString))
headNode = newNode;
//rest of the nodes
StringLLNode currNode = headNode;
while(currNode != null)
if (currNode.getData().equalsIgnoreCase(aString))
newNode.setNext(currNode);
//System.out.println("It went THROUGH");
currNode = currNode.getNext();
//Last Node
if (currNode != null)
newNode.setNext(headNode);
}Given a linked list [A-E] we have: A => B => C => D => E. Each Node is referencing the node to it's right, so A references B, D references E etc.
For example take aString = "A" and newString = "AB". Your code suggests the following:
1. Create new_node "AB"
2. if head[A] equals aString[A], TRUE
2.a head = new_ node
Now the resulting linkedlist is the following:
AB => Null
what happened to the rest of the list?
Now we go on to your updated example, we result in the following list:
A => AB => Null
hmm do you see a pattern here? when inserting a new node we are disregarding any reference to the tail of the list.
Extending on that idea we have the following pseudo code
1. if node to be inserted
1.a new_node.next = list_tail
1.b current_node.next = new_node
A => B => C => D => E, where newnode=AA
AA => B => C => D => E //using 1.a
A => AA => B => C => D => E //using 1.b
Mel -
Using compareTo() in a Linked List Please Help!!
I'm trying to compare strings in a Linked List and it throws a null pointer exception somewhere in the method smallest() which is where i have the strings(nodes) comparing each other. I've been Trying to find the answer for two days now and I've gotten nowhere. PLEASE HELP! The code is as follows:
public String smallest()
// Returns smallest String in StringLog in terms of lexicographic ordering.
//Precondition: StringLog is not empty.
LLStringNode node;
LLStringNode node2;
LLStringNode node3 = log;
node = log;
node2 = log;
String smallString = "Bob";
boolean notNull = (node != null);
boolean notNull2 = (node2 != null);
while (notNull && notNull2)
System.out.println(node.getInfo() + " " + node2.getInfo());
if (node.getInfo().compareTo(node2.getInfo()) <= 0)
node3 = node;
node2 = node2.getLink();
smallString = node3.getInfo();
else if (notNull && notNull2)
node3 = node2;
node = node.getLink();
smallString = node3.getInfo();
smallString = node3.getInfo();
return smallString;
}I've inserted a line of code that shows the output of the method in the test driver before it throws the exception it is as follows: note I have already input strings through the test driver.
Choose an operation:
1: insert(String element)
2: howMany(String element)
3: clear()
4: contains(String element)
5; isFull()
6; isEmpty()
7: size()
8: uniqInsert(String element)
9: getName()
10: toString()
11: smallest()
12: Stop testing
11
Exception in thread "main" lamb lamb
lamb cat
cat cat
cat apple
apple apple
apple dog
apple thing
apple girl
apple boy
java.lang.NullPointerException
at LinkedStringLog.smallest(LinkedStringLog.java:189)
at CMPS39001.main(CMPS39001.java:121)Below is the full class of LinkedStringLog which contains the smallest() method(you may or may not need this i'm not sure)
{codepublic class LinkedStringLog implements StringLogInterface
protected LLStringNode log; // reference to first node of linked
// list that holds the StringLog strings
protected String name; // name of this StringLog
public LinkedStringLog(String name)
// Instantiates and returns a reference to an empty StringLog object
// with name "name".
log = null;
this.name = name;
public void insert(String element)
// Precondition: This StringLog is not full.
// Places element into this StringLog.
LLStringNode newNode = new LLStringNode(element);
newNode.setLink(log);
log = newNode;
public int howMany(String element)
// Returns an int value of how many times it occurs in StringLog
int eleCount = 0;
LLStringNode node;
node = log;
while (node != null)
if (element.equalsIgnoreCase(node.getInfo()))
eleCount ++;
node = node.getLink();
else
node = node.getLink();
return eleCount;
public boolean isFull()
// Returns true if this StringLog is full, false otherwise.
return false;
public boolean isEmpty()
// Returns true if StringLog is empty, it otherwise returns false.
boolean isNull = true;
LLStringNode node;
node = log;
boolean searchEmpty = (node != null);
if (searchEmpty)
isNull = false;
return isNull;
return isNull;
public boolean uniqInsert(String element)
// Inserts element in stringLog unless an identical string already exists in the StringLog
LLStringNode node;
node = log;
boolean found = false;
boolean searchMore;
searchMore = (node != null);
while (searchMore && !found)
if (element.equalsIgnoreCase(node.getInfo()))
return found;
else
node = node.getLink();
searchMore = (node != null);
if (found = true)
LLStringNode newNode = new LLStringNode(element);
newNode.setLink(log);
log = newNode;
return found;
public int size()
// Returns the number of Strings in this StringLog.
int count = 0;
LLStringNode node;
node = log;
while (node != null)
count++;
node = node.getLink();
return count;
public boolean contains(String element)
// Returns true if element is in this StringLog,
// otherwise returns false.
// Ignores case difference when doing string comparison.
LLStringNode node;
node = log;
boolean found = false;
boolean moreToSearch;
moreToSearch = (node != null);
while (moreToSearch && !found)
if (element.equalsIgnoreCase(node.getInfo())) // if they match
found = true;
else
node = node.getLink();
moreToSearch = (node != null);
return found;
public void clear()
// Makes this StringLog empty.
log = null;
public String getName()
// Returns the name of this StringLog.
return name;
public String toString()
// Returns a nicely formatted string representing this StringLog.
String logString = "Log: " + name + "\n\n";
LLStringNode node;
node = log;
int count = 0;
while (node != null)
count++;
logString = logString + count + ". " + node.getInfo() + "\n";
node = node.getLink();
return logString;
public String smallest()
// Returns smallest String in StringLog in terms of lexicographic ordering.
//Precondition: StringLog is not empty.
LLStringNode node;
LLStringNode node2;
LLStringNode node3 = log;
node = log;
node2 = log;
String smallString = "Bob";
boolean notNull = (node != null);
boolean notNull2 = (node2 != null);
while (notNull && notNull2)
System.out.println(node.getInfo() + " " + node2.getInfo());
if (node.getInfo().compareTo(node2.getInfo()) <= 0)
node3 = node;
node2 = node2.getLink();
smallString = node3.getInfo();
else if (notNull && notNull2)
node3 = node2;
node = node.getLink();
smallString = node3.getInfo();
smallString = node3.getInfo();
return smallString;line 189 is
if (node.getInfo().compareTo(node2.getInfo()) <= 0)and the other line mentioned is just the call.
But that line runs several times until a certain point and then throws the error. Example, in the test driver every time that line is ran it is outputting the nodes in the test driver that I posted. -
Help with copying contents of file to link list please
Hi,
Below is a snippet of code I am playing with. As you can see I have created a LinkList, I now need to copy the contents of a csv file in to that list. The file is several lines long and I need each line in the list.
I know how to add to the list manually i.e.,
list.add("First entry in list");
Could someone help me out with this please.
Many thanks.
(***CODE***)
private LinkedList list = new LinkedList();
public LinkTest()
// ** List content START **
// Open the file today.csv
File inFile = new File("C:\\today.csv");
// Create a file stream, wrapping the file
FileReader fileReader = new FileReader(inFile);
// Create a second wrapper,
BufferedReader bufReader = new BufferedReader(fileReader);
// Read in the first line...
String s;
s = bufReader.readLine();
list.add(s);
StringTokenizer st = new StringTokenizer(s);
while (st.hasMoreTokens())
System.out.println(st.nextToken());
// ** List content END **
I looked at your code and I thought, what's the question for, it's already adding lines to the list. And then I looked again and had the same thought. The third time I looked I noticed you didn't code the loop that read all the lines from the file. Silly me, I thought your question had something to do with linked lists.
Anyway, to answer your real question, which is how do you read all the lines from a text file:while ((s = bufReader.readLine()) != null) {
// do something with the String s here
// such as adding it to a linked list
} -
Anyone help me please~ many thanks! C++ linked list
I've written a Microsoft C++ code, using a linked list to store the result which is sent by a device.
The head node and tail node of linked list is put into a class, and all methods are set to 'static' to manipulate the data inside the linked list. So that different thread can access to it.
At first, everything runs ok in native environment,( i compile it as a .exe file)....
However, when I export it into DLL and run inside java code using JNI. The linked list was gone (head node & tail node lost). It seems that JVM try to re-initialize the head node everytime I invoke those method.
Hence, I modify the class which handle the link list, set all its methods into non-static, and define a global variable. Yet, another problem came out... Acess Violation error... it seems again the adress(pointer) of head node can't be modified...
Is there any other way to solve this problem?? I mean, I want the head node remains valid for each time of java method is called.Too vague.
If you could show us some relevant Java and JNI C++
code.
Please paste your code between code tags exactly like
this:
your codeYou may read the [url
http://forum.java.sun.com/help.jspa?sec=formatting]For
matting tips for more information.Here you are:
this is the header definition of the linked list handler, all functions are set to be non-static
typedef struct DeviceLinkList{
char *deviceNumber;//device of monitor device
int result;
DeviceLinkList *nextNode;
DeviceLinkList *prevNode;
} DeviceLinkList;
class DeviceListHandler
public:
DeviceLinkList *headNode = NULL;
DeviceLinkList *tailNode = NULL; //Moving to last of the entry
void addNode(char *device); //add monitor device
void deleteNode(char *device); //remove after device is stop monitorred
void printAll();
void setResult(char *device);
private:
DeviceLinkList *searchNode(char *device);
};Here is the implementation of my code in function 'addNode':
void DeviceListHandler::addNode(char *device)
printf("Creating Link List.\n");
printf("Head is %d\n" ,headNode);
if(headNode != NULL) //create new node from empty --> Access Violation Exception start from here
DeviceLinkList *temp = new DeviceLinkList;
temp->deviceNumber = device;
temp->nextNode = NULL;
temp->prevNode = tailNode;
tailNode->nextNode = temp;
tailNode = temp; //move tailNode point to the last entry
printf("Connecting to Tail Node done\n");
else
DeviceLinkList *temp = new DeviceLinkList;
printf("Creating Head\n");
temp = new DeviceLinkList;
temp->deviceNumber = device;
temp->nextNode = NULL;
temp->prevNode = NULL;
printf(".....DONE...!!!\n");
headNode = temp;
tailNode = headNode;
printf("Finish Head-Tail Node creation\n");
printf("Creation Done\n");
}This is the one of function which export to JNI:
JNIEXPORT void JNICALL Java_PBXdll_monitorStart (JNIEnv * env, jobject obj, jstring callingdevice)
char device[MAX_CstaDialingNumber];
strcpy(device,env->GetStringUTFChars(callingdevice, 0));
printf("Monitoring device: %s\n", device);
startMonitor(device);
deviceList -> addNode(device); // deviceList is the global variable
}so...when i call the method monitorStart in java... it terminated abnormally with a Access Violation Exception.....the linked list can't be created. -
Please help me :'( , I really need help in Linked List & Recursion program.
Hi everybody..
I hope all of you are ok..
I'm new member in this forum and I hope anyone can help me in Linked List $ Recursion issue..
I should write a Java program that implements a linked list of objects. This program / class will have the following methods:
1- //print each node starting from startNode upto the end node in the list
void writeList(Node startNode)
2- //insert a new element to the end of the list
void insertEnd(Object element)
3- //Print each element statring from first element in list to the last element then start //printing each element from the last element to the first element
void writeMirror()
4- //delete the last node.
void deleteEnd()
5- //returns the number of the nodes in the list.
int lengthList(ListNode x)
Implement the above methods using the following restrictions:
1- All above methods must be implemented as a recursive method.
2- For the given linked list class, there is only a head reference
variable, pointing the beginning of the list. Thus there is no last or
end reference variable.
I don't know how to write this program :'( ..
I need your help guys and I will be so happy if anyone can do it for me ..
The sad girl
MaRia :(Any body can give me any idea any hint that may help
me ??Hint that will help you: get a personal tutor. This is the wrong place to learn how to program. And you definitely won't learn by having your homework done for you.
Oh, and I don't care at all that your hamster has diarrhea, your boyfriend broke up with you, both of your parents are dead and unemployed, that you have to look after your 231 siblings all by yourself and that you're forced to take this class and rather want to do something completely different.
Heard it all before. -
Please help me about samples project with COM UI DI
I run sample project
C:\Program Files\SAP\SAP Business One SDK\Samples\COM UI DI\VB.NET\AddColumn
but i can't test becoz i don't know screen b1 matching with oForm.TypeEx = "65270"
Please tell me about screen b1 for test this codeI don't know the answer right away, but:
- take a look into the FAQ in the Wiki (https://www.sdn.sap.com/irj/sdn/wiki?path=/display//b1/faq)
- there go to "UI Forms"
...and find these links (mid-term we want of course more information directly available in the Wiki...):
List of form IDs:
/people/lutz.morrien3/blog/2004/10/01/all-sap-business-one-formtypes-at-one-look
Update: https://weblogs.sdn.sap.com/cs/user/view/cs_msg/14059
The hints in the update will help you to get the title of the form - and thus will give you a hint where to look for the form. For your convenience I have copied the "relevant code here:
Dim Info As FormInfo = Application.ResourceData.GetFormInfo("65270")
FormInfo.Title
...gives you the title of the form -
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 -
Putting a class of objects in a Linked List?
Hi,
I copied a program from a book and I want to edit it and put studentRecord class in the Linked List. I've tried to play about with datum, but everything I try doesn't work. Can someone help me out? How could I put studentRecord in the LinkedList?
import java.io.*;
class IO
static BufferedReader keyboard = new
BufferedReader(new InputStreamReader(System.in));
static PrintWriter screen = new PrintWriter(System.out, true);
class studentRecord
private String name;
private int IDNumber;
class LinkedList
class Node
protected Object datum;
protected Node link;
public Node() {}
public Node(Object item, Node pointer)
datum = item;
link = pointer;
private Node head;
private Node tail;
private Node temporary;
private int nodeCount = 0;
//constructor
public LinkedList()
head = null;
tail = null;
temporary = null;
//method to insert an object into the linked list
public void insert(Object datum)
if (head == null) // list empty
head = new Node(datum, head);
tail = head;
else
temporary = new Node(datum, temporary);
tail.link = temporary;
tail = temporary;
temporary = null;
nodeCount++;
Full program can be found: http://dil3mma.tripod.com/LinkedList.txt
Thanks in advance.Hi jverd,
Thanks for replying. I've tried to change the program liked you said but there is 1 error I can't seem to fix(Im sure there are more tho). The error is "cannot resolve symbol" I typed in caps the line it happens on so it's easy to see. Any idea what it could be? Is it cause I'm comparing a String with Object?
import java.io.*;
class IO
static BufferedReader keyboard = new
BufferedReader(new InputStreamReader(System.in));
static PrintWriter screen = new PrintWriter(System.out, true);
class sRecord
private String name;
private int IDNumber;
class LinkedList
class Node
protected sRecord datum;
protected Node link;
public Node() {}
public Node(sRecord item, Node pointer)
datum = item;
link = pointer;
private Node head;
private Node tail;
private Node temporary;
private int nodeCount = 0;
//constructor
public LinkedList()
head = null;
tail = null;
temporary = null;
//method to insert an object into the linked list
public void insert(sRecord datum)
if (head == null) // list empty
head = new Node(datum, head);
tail = head;
else
temporary = new Node(datum, temporary);
tail.link = temporary;
tail = temporary;
temporary = null;
nodeCount++;
//method to delete an object from the linked list
public boolean delete(Object scrap)
Node previous = head;
//for every node in the linked list
for (Node current = head; current != null; current = current.link)
//node to be deleted is at the head of the list
if (current.datum.equals(scrap) && previous == current)
head = current.link;
if (head == null) tail = null;
nodeCount--;
return true;
//node to be deleted is after the first node and before the last
else if (current.datum.equals(scrap) && (current.link != null))
previous.link = current.link;
nodeCount--;
return true;
//node to be deleted is at the ned of list
else if (current.datum.equals(scrap) && (current.link == null))
tail = previous;
previous.link = null;
nodeCount--;
return true;
previous = current;
return false;
//method to display the contents of a linked list
public void displayList()
Node temporary = head;
if (head == null)
IO.screen.println("linked list is empty");
return;
while (temporary != null)
IO.screen.println(temporary.datum);
temporary = temporary.link;
//method to return true if the linked list is empty
public boolean isEmpty()
return (nodeCount == 0);
//method to return the number of nodes in the linked list
public int nodes()
return nodeCount;
//method to display a menu to insert data into the linked list
static private char menu()
char response = '\u0000';
IO.screen.println("Do you want to ");
IO.screen.print("nsert, [D]elete, [L]ist, [E]xit? ");
IO.screen.flush();
boolean done=false;
do
try
String data = IO.keyboard.readLine();
response = Character.toUpperCase(data.charAt(0));
done = true;
catch (Exception e)
IO.screen.println("Please input a single character I, D, L or E");
} while (! done);
return response;
static public void main(String[] args) throws IOException
LinkedList list = new LinkedList();
String datum;
char choice;
//get information from menu
choice = menu();
for (;;)
//Menu
switch (choice)
case 'I' :
IO.screen.println("type quit to finish input");
IO.screen.print("Enter a word ");
IO.screen.flush();
datum = IO.keyboard.readLine();
while (! datum.equals("quit"))
THE ERROR HAPPENS HERE ON THIS LINE list.insert(datum.name);
IO.screen.print("Enter another word");
IO.screen.flush();
datum = IO.keyboard.readLine();
break;
case 'D' :
//if list is empty deletion not possible
if (list.isEmpty())
IO.screen.println("linked list is empty");
break;
IO.screen.println("type quit to finish input");
IO.screen.print("Delete? ");
IO.screen.flush();
datum = IO.keyboard.readLine();
while (! datum.equals("quit"))
if (list.delete(datum))
IO.screen.println(datum+" was scrapped!");
//if list is empty deletion is not possible
if (list.isEmpty())
IO.screen.println("linked list is empty");
break;
IO.screen.print("Delete? ");
IO.screen.flush();
datum = IO.keyboard.readLine();
break;
case 'L' :
list.displayList();
IO.screen.println("number of nodes " + list.nodes());
break;
case 'E' : System.exit(0);
//get information from menu
choice = menu(); -
Sort Linked List...
I need help sorting a linked list.
So far, in my sort method I have...
public LinkedList sort();
LinkedList newList = new LinkedList();
Node ref;
Node temp = new Node(head.getempID(); head.getempLast(), head.getempFirst(); head.getempDept(), head.getempSalary());
for(ref = head; ref != null; ref.getNext());
if(ref.getempID() <= temp.getEmpID());
temp = (ref.getempID(), ref.getempLast(), ref.getempFirst(), ref.getempDept(), ref.getempSalary());
newList.insert(temp); //???????
return newList();
// As you can tell, each one of my node's consists of an employee's id number, last name, first name, department, and salary...I need to sort the linked list by the employee's ID number. I can not figure out how to swap nodes though. PLEASE HELP A KID OUT!!!I was worng, my last data structure lecture today(I hope).
| | | | | | | | | |
head->| Node1 |---->| Node2 |---->| Node3 |---->| Node4 |---etc-->| NodeN |->null
| | | | | | | | | |
Q: How do you swap node2 with node3?
A: Think about it! Look at a picture if thats what you need. Draw the lines of reference to figure it out.
1. Where does node1.next need to point to, how about node2.next, or node3.next?
3. How do you change these without losing a node, are you going to need a temp?
4. What about special case(switching node1 and node2)?
This is simple problem solving skills. I assume you have built the list yourself,
so you have the basic knowledge base needed. -
Can I use Links list to make a selection in a finder window?
I have a .indd file with about 75 placed graphics. The graphics are in a folder with 150+ images. I want to delete all the unused images from this folder. Is there a way to "select in finder" those images included in the indd file? I'm trying to avoid manually going back and forth from the Links list to the Finder window to make this selection. (Yes, I've admonished the author to please clean up their folders in advance, but that didn't happen and now I have 10 book chapters with this same problem this my motivation to solve via computer automation.)
You didn't give your ID version. In CS3, I'd package the file with links, empty the image folder and then copy back the linked images from the package to the original folder. Then delete the package.
Noel -
How to get the description value of the hyperlink field in the link list for xslt list view webpart ? i.e how do I get the value of description in the XSLT that I provide for XslLink?
Hi,
If there is a hyperlink field in your list view, then there would be a variable “$desc” in the xslt code, you can call it like this:
<xsl:value-of select="$desc"/>
Here are two links with code samples about how to customize the the rendering of a hyperlink field for your reference:
https://social.msdn.microsoft.com/Forums/sharepoint/en-US/68b05f40-9b62-485b-ba8e-4684a7e34899/truncate-url-in-xslt-view
http://sharepoint.stackexchange.com/questions/58672/painless-way-to-display-hyperlink-as-url
More information about XSLT language:
http://www.w3schools.com/xsl/
Thanks
Patrick Liang
Forum Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support,
contact [email protected]
Patrick Liang
TechNet Community Support
Maybe you are looking for
-
Safari won't download properly
I deleted my realmedia .plist, which perhaps wasn't a good idea, and now when i go this website: http://www.kcm.org/media/webcasts/index.php , I'm unable to download the mp3s from it, whereas before Safari just opened up the download window, download
-
How do I get a full screen canvas back
I'm a 20 year user -- today I lost 90 percent of my canvas - an inaccurate way of saying the screen on which the canvas sits is 1.5" wide and 22 " tall. The little thingy that one clicks on and holding down the mouse to drag it to full screen is not
-
How much Hard drive space lion uses
How do I find out how HD space my upgraded Lion OS and Apps are using? I am purchasing a new iMac with 256GB SSD for the main drive and 1 TB for the secondary drive, but I want to make sure that 1. My current apps and lion will fit on the new HD as
-
Since we all purchased this item for the Flash on the Go experience let make sure we have the following in the next OS update please Stereo Bluetooth (Can't sync with my Car Stereo) Ford Focus for those long road trips NetFlix App paying subscriber H
-
Hi All, How we can assign a different vendor as a Good Supplier for a particular vendor. I have checked in main vendor master partner profile not able to find the same. Thanks Chandru