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

  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

  Calculate worst-case run-time complexity of algorithm

Calculate the worst-case run-time complexity of your algorithm and prove optimality of the solution it gives. Suppose that the road is a straight line with a western end and an eastern end.

  Generalize 2-3 algorithms for insert and delete

Generalize the 2-3 algorithms for INSERT and DELETE to K-J trees, where non-leaf vertices have between K and J children for fixed integers K >=2, and J>= 2K-1.

  Creating visual studio.net web application

Make a Visual Studio.NET 2005 web application with one aspx form. Place a CheckBoxList, TextBox, Button, and Label control on the form.

  Entity relationship diagrams

Discuss why are Entity Relationship Diagrams an important initial stage in developing databases? Who would be the initial parties interacting to develop the ERDs?

  Devise ef?cient algorithm for computing probability

Given the probabilities r1, · · · , rn, the costs c1, · · · , cn, and the budget B, ?nd the redundancies m1, · · · , mn that are within the available budget and that maximize the probability that the system works correctly. Devise an ef?cient algo..

  Describe algorithm that finds maximum feasible flow in graph

Describe an algorithm that finds a maximum feasible flow in G. Denote by MF(|V|, |E|) the worst-case running time of an ordinary maximum flow algorithm.

  Database design process

A college course may have one or more scheduled sections, or may not have a scheduled section. Attributes of COURSE include Course_ID, Course_Name, and Units.

  Write schedule produced by earliest deadline first algorithm

Given below are two sets of real-time, periodic tasks. For (a), will the schedule produced by Earliest Deadline First algorithm meet all the deadlines?

  Question related to ms excel

Discuss how do I insert a row in multiple tables on different sheets in the same workbook? I have twelve sheets, one for every month, and the sheets are exactly the same.

  Create algorithm prompt for and receive employee number

Create algorithm which will prompt for and receive the employee number from operator at terminal. Your program is to search array of valid employee numbers to check that employee number is XXXXX,

  Explaining effective customer relationships and loyalty

Paws'n Tails is an online pet shop that wants to influence what customers buy and builkd effective customer relationships and loyalty.

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