Created a linked list class

Assignment Help Data Structure & Algorithms
Reference no: EM13165202

created a linkedlist class,the set() method and listiterator() method. I need someone to finish for me.

 

here is what i got so far:

 

import java.util.Iterator;

import java.util.ListIterator;

import java.util.NoSuchElementException;

 

 

public class MyLinkedList<Product> {

private Node<Product> head = null;

private Node<Product> tail = null;

private Node<Product> temp = null;

 

private int counter = 0;

public MyLinkedList() {

}

public int size(){return counter;}

 

public Product get(int position){

assert (position >= 0 && position < size());

temp = head;

for(int i = 0; i < position; i++) temp = temp.next;

return temp.element;

}

 

public void add(Product element) {

if (head == null) {

head = tail = new Node<Product>();

head.element = element;

head.next = tail;

tail = head;

}else{

tail.next = new Node<Product>();

tail = tail.next;

tail.element = element;

}

counter++;

 

}

 

/*public void set(int position, Product element) {

if (position == size()) {

add(element);

return;

} else if (position == 0) {

 

}

 

}*/

public void set(int inLayer, Product element) {

if (head == null) {

head = tail = new Node<Product>();

head.element = element;

head.next = tail;

tail = head;

}else{

tail.next = new Node<Product>();

tail = tail.next;

tail.element = element;

}

counter++;

}

public ListIterator<Product> iterator() {

return ListIterator<Product>();

}

Node<Product> current = head;

 

boolean hasNext() {

return (current.next != null);

}

 

Product next() {

if (!hasNext()) {

throw new NoSuchElementException();

}

current = current.next;

return current.value;

}

 

 

Reference no: EM13165202

Questions Cloud

What resources did you use in preparing this tax return : What resources did you use in preparing this tax return?  Provide references to page numbers in your textbook and specific addresses within the IRS website.
What is the compound empirical formula : a 175.0g sample of a compound contains 56.15g C, 9.43g H, 74.81g O, 13.11g N, and 21.49g Na. What is the compound's empirical formula?
State how many moles of oxygen atoms : 1. How many CO2 molecules are needed to produce 1 glucose molecule (in photosynthesis)? 2. How many moles of oxygen atoms are in 1 mole of calcium phosphate?
Calculate the mass of lycopene : (a)how do I calculate the concentration of the lycopene solution in the spectrophotometer cell before isomerization, given that the molar absorptivity of lycopene at 471 nm is 1.86 x 10^4. (b) Calculate the mass of lycopene in 3.0mL of the solutio..
Created a linked list class : created a linkedlist class
How many grams of naoh should we have used : The molar mass of corn oil is 890g/mole. How many moles and how many grams of sodium hydroxide are required to react with the 15mL (13.7g) of corn oil? Show your calculations.
Develop an interface evaluation questionnaire : Develop an interface evaluation questionnaire that contains 20 generic questions that would apply to most interfaces.
How many ozone molecules are in a liter : If the pressure exerted by ozone, O3, in the stratosphere is 3.0*10^-3 atm and the temperature is 250 K, how many ozone molecules are in a liter?
Decomposition for r = (a,b,c,d,e ) : Give a good decomposition for R = (A,B,C,D,E ) with the following functional dependencies:

Reviews

Write a Review

Data Structure & Algorithms Questions & Answers

  Explaining simple symmetric encryption algorithm

Consider a simple symmetric encryption algorithm as follows:Is it a problem if the first block of input happens to be the same as the key? Explain why?

  Explain algorithm from is optimal by proving lower bound

Illustrate that your algorithm from (a) is optimal by proving lower bound of n - k on number of comparisons required to solve the problem.

  Users and it organizations arm against phishing attacks

How users and IT organizations must arm themselves against these attacks?

  Binary search algorithm

Use the binary search algorithm to seach the list. (You might need to modify the algorithm given in this chapter to count the number of comparisons.)

  Interchange contents of working registers

Make a stack at 1000h and use the stack to interchange the contents of all of working registers. Exchange AX with DX, BX with CX, and DI with SI.

  Define a federated database

Define a federated database and discuss why are federated databases becoming increasingly common? Provide examples of databases in your current or previous work environment

  Sketch dynamic programming tables for knapsack problem

Sketch Dynamic Programming Tables (one for calculating optimal value and one for keeping track of items used in getting optimal value) for 0/1 Knapsack Problem given below and illustrate your final result.

  Question about database administration

Should the data administrator really be on the same level as the DBA, generally somewhat low in corporate hierarchy or should this person have an elevated level of importance?

  Creating an asp.net application

Design an ASP.NET application using Visual Studio .NET 2003. Your application with at least one web form and 5-different types of controls.

  Question about unix and shell scripting

Explain the results of executing each of the following grep commands in your home directory.

  Explain benefits of isdn

Sometimes ISDNs are used in locations that do not support DSL or cable modem connections. Your selections may be analog modems or an ISDN connection in those remote locations.

  Using command line options in bash shell script

Design a script that will permit the user to enter one of several choices from the command line. The specific requirements are as follows:

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd