Constructors/Destructors - Initialize your data. Allocate memory if using a dynamically allocated array. The destructor should deallocate the memory. The constructor should take a single int variable to determine the size. If no size is specified (default constructor), then the size should be set to 50.
operator[](size_t) - This should return the location with the matching index. For example if given an index of 3, you should return the location at index 3 in the list.
Location class/struct - This class/struct should have the following public member variables: name, address, city, postal code, province, latitude, longitude, minimum price range, and max price range.
#pragma once
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
// "Location.h"
using std::getline;
using std::ifstream;
using std::string;
using std::stringstream;
class Location {
public:
string name, address, city, postalCode, province;
double latitude, longitude;
int priceRangeMax, priceRangeMin;
};
class PizzaZine {
private:
Location *pizzaLocations;
size_t size;
public:
// PizzaZine(const size_t & = 50);
// work
PizzaZine() { pizzaLocations = new Location[50]; }
~PizzaZine() { delete[] pizzaLocations; }
Location &operator[](size_t);
// This function is implemented for you
void readInFile(const string &);
};
// PizzaZine::PizzaZine() { pizzaLocations = new Location[50];
}
// PizzaZine::~PizzaZine() { delete[] pizzaLocations;
}
Location &PizzaZine::operator[](size_t index) { return pizzaLocations[index]; } // this is where the code ends of my written code rest is skeleton
void PizzaZine::readInFile(const string &filename)
{
ifstream inFile(filename);
Location newLoc;
string line;
string cell;
// Read each line
for (int i = 0; i < size; ++i) {
// Break each line up into 'cells'
getline(inFile, line);
stringstream lineStream(line);
while (getline(lineStream, newLoc.name, ',')) {
getline(lineStream, newLoc.address, ',');
getline(lineStream, newLoc.city, ',');
getline(lineStream, cell, ',');
if (!cell.empty()) {
newLoc.postalCode = stoul(cell);
}
getline(lineStream, newLoc.province, ',');
getline(lineStream, cell, ',');
newLoc.latitude = stod(cell);
getline(lineStream, cell, ',');
newLoc.longitude = stod(cell);
newLoc.priceRangeMin = -1;
getline(lineStream, cell, ',');
if (!cell.empty()) {
newLoc.priceRangeMin = stoul(cell);
}
newLoc.priceRangeMax = -1;
getline(lineStream, cell, ',');
if (!cell.empty() && cell != "\r") {
newLoc.priceRangeMax = stoul(cell);
}
pizzaLocations[i] = newLoc;
}
}
}
the main cpp shouldnt matter as much as all of that was skeleton code
main.cpp:15:15: error: no matching constructor for
initialization of 'PizzaZine'
PizzaZine top10(10);
^ ~~
./PizzaZine.h:20:7: note: candidate constructor (the implicit copy
constructor) not viable: no known conversion from
'int' to 'const PizzaZine' for 1st argument
class PizzaZine {
^
./PizzaZine.h:28:3: note: candidate constructor not viable:
requires 0 arguments, but 1 was provided
PizzaZine() { pizzaLocations = new Location[50]; }
^
main.cpp:29:15: error: no matching constructor for initialization
of 'PizzaZine'
PizzaZine top200(200);
^ ~~~
./PizzaZine.h:20:7: note: candidate constructor (the implicit copy
constructor) not viable: no known conversion from
'int' to 'const PizzaZine' for 1st argument
class PizzaZine {
^
./PizzaZine.h:28:3: note: candidate constructor not viable:
requires 0 arguments, but 1 was provided
PizzaZine() { pizzaLocations = new Location[50]; }
^
main.cpp:36:15: error: no matching constructor for initialization
of 'PizzaZine'
PizzaZine top400(400);
^ ~~~
./PizzaZine.h:20:7: note: candidate constructor (the implicit copy
constructor) not viable: no known conversion from
'int' to 'const PizzaZine' for 1st argument
class PizzaZine {
^
./PizzaZine.h:28:3: note: candidate constructor not viable:
requires 0 arguments, but 1 was provided
PizzaZine() { pizzaLocations = new Location[50]; }
^
3 errors generated.
In: Computer Science
##### Volume #####
# set and get
>>> v = Volume()
>>> v.set(5.3)
>>> v
Volume(5.3)
>>> v.get()
5.3
>>> v.get()==5.3 # return not print
True
>>>
# __init__, __repr__, up, down
>>> v = Volume(4.5) # set Volume with value
>>> v
Volume(4.5)
>>> v.up(1.4)
>>> v
Volume(5.9)
>>> v.up(6) # should max out at 11
>>> v
Volume(11)
>>> v.down(3.5)
>>> v
Volume(7.5)
>>> v.down(10) # minimum must be 0
>>> v
Volume(0)
# default arguments for __init__
>>> v = Volume() # Volume defaults to 0
>>> v
Volume(0)
# can compare Volumes using ==
>>> # comparisons
>>> v = Volume(5)
>>> v.up(1.1)
>>> v == Volume(6.1)
True
>>> Volume(3.1) == Volume(3.2)
False
# constructor cannot set the Volume greater
# than 11 or less than 0
>>> v = Volume(20)
>>> v
Volume(11)
>>> v = Volume(-1)
>>> v
Volume(0)
>>>
##### partyVolume #####
>>> partyVolume('party1.txt')
Volume(4)
>>> partyVolume('party2.txt')
Volume(3.75)
>>> partyVolume('party3.txt')
Volume(0.75)
# make sure return not print
>>> partyVolume('party1.txt')==Volume(4) # return not print
True
>>> partyVolume('party2.txt')==Volume(3.75)
True
>>> partyVolume('party3.txt')==Volume(0.75)
True
use python3.7
In: Computer Science
Java
|
You entered 111 Its base 10 equivalent is 7 |
|---|
SPECIFIC RESTRICTIONS FOR THIS ACTIVITY
You should develop your own method, do not use Integer.parseInt (String s, int radix)
*********************************************************************************************************************************
This is my code so far, it works but once I ask the user to try another binary. The Binary doesn't come out right
***********************
import java.util.Scanner; // Needed for the Scanner class
import java.io.*; // Needed for File I/O classes
public class Binary
{
public static void main(String[] args) throws IOException
{
String userEntry; // To hold the userEntry
String again = "y";
int binary = 0;
int bin = 0;
int decimal = 0;
int i = 0;
// Create a Scanner object to read input.
Scanner keyboard = new Scanner(System.in);
PrintWriter outputFile = new PrintWriter("outDataFile.txt");
while (again.equalsIgnoreCase("y"))
{
// Get the user's name.
System.out.println("Enter a Binary String: ");
userEntry =
keyboard.nextLine();
System.out.println("\nYou entered the number: " + userEntry
);
outputFile.println("You entered the number: " + userEntry);
//validate
userName
userEntry =
checkUserEntry (userEntry);
binary =
Integer.parseInt(userEntry);
boolean result =
isBinary(binary);
if(result ==
true)
{
bin =
binary;
while(binary
!= 0)
{
decimal +=
(binary%10)*Math.pow(2, i++);
binary = binary
/10;
}
System.out.println("its base 10 equivalent of " + bin +" is " +
decimal );
outputFile.println("its base 10 equivalent of " + bin +" is " +
decimal );
}
else
{
System.out.println("This is not a Binary Number, try again");
}
System.out.println("\n\nWould
you like to try another number? (y/Y). Anything else will
quit");
again = keyboard.nextLine();
}
outputFile.close();
System.out.println("Goodbye");
}//end main
public static boolean isBinary(int binary)
{
int Input = binary;
while (Input !=
0)
{
if (Input % 10 > 1)
{
return
false;
}
Input = Input /
10;
}
return
true;
}
public static String checkUserEntry (String userAnswer)
{
int userAnswerLength = userAnswer.length();
int counter = 0;//to iterate through the string
// Create a Scanner object to read input.
Scanner keyboard = new Scanner(System.in);
while(userAnswerLength==0)
{
System.out.println("That is not a number >=
0, try again");
userAnswer = keyboard.nextLine();
userAnswerLength = userAnswer.length();
}
while(counter < userAnswerLength)
{
if(!Character.isDigit(userAnswer.charAt(counter)))
{
System.out.println("That is not a number >=
0, try again ");
userAnswer = keyboard.nextLine();
userAnswerLength = userAnswer.length();
counter = 0;
}
else
{
counter++;
}
while(userAnswerLength==0)
{
System.out.println("That is not a number >=
0, try again");
userAnswer =
keyboard.nextLine();
userAnswerLength =
userAnswer.length();
}
}
return userAnswer;
}
}//end class ValidateUserName
In: Computer Science
Please do Part III
Part I
Problem statement:
Given an array of 'n' non-duplicate integers, find pairs of integers from the array that make the sum equal to K.
Eg. [1, 2, 7, 11, 6, 9, 5] K= 12
Soln: (1,11), (7,5).
Part II
Write an Oracle for testing this program using Data Flow Testing. As usual, write down test cases in a tabular form with reasons, inputs, expected output etc.
Part III
1. Identify the basic blocks in your program and draw the flow graph
2. Identify as many independent paths as possible with a minimum of three paths)
3. Classify these as simple paths and loop-free paths
4. Identify the definition, P-uses, and C-uses throughout the program
5. Identify the def-use associations of variables if any.
In: Computer Science
(Problem is from the textbook Data Structures using C++)
Add a function to the dateType class.
The function's name is compareDates.
Its prototype is
int compareDates(const dateType& otherDate;
The function returns -1 if otherDate is greater than than this date
The function returns 0 if otherDate equals this date
The function returns 1 if otherDate is less than this date
Examples
dateType d1(1, 1, 2019);
dateType d2(11,1, 2019)
d1.compareDates(d2) returns -1
d2.compareDates(d1) returns 1
d2.compareDates(d2) returns 0
<<<<< dateType.h >>>>>>
#ifndef H_addressType
#define H_addressType
#include
#include
using namespace std;
class addressType
{
public:
void setStreet(string myStreet);
void setCity(string mCity);
void setState(string myState);
void setZIP(int myZIP);
string getStreet() const;
string getCity() const;
string getState() const;
int getZIP() const;
void printAddress() const;
addressType(string = "", string = "", string = "",
int = 0);
private:
string street;
string city;
string state;
int ZIP;
}
#endif
void addressType::setStreet(string myStreet)
{
street = myStreet;
} // end function setStreet
void addressType::setCity(string myCity)
{
city = myCity;
} // end function setCity
void addressType::setState(string myState)
{
state = myState;
} // end functioni setState
void addressType::setZIP(int myZIP)
{
ZIP = myZIP;
} // end function setZIP
string addressType::getStreet() const
{
return street;
} // end function getStreet
string addressType::getCity() const
{
return city;
} // end function getCity
string addressType::getState() const
{
return state;
} // end function getState
int addressType::getZIP() const
{
return ZIP;
} // end function getZIP
void addressType::printAddress() const
{
cout << "\n\t" << getStreet() << ", " << getCity()
<< "\n\t" << getState() << " - " << getZIP();
} // end function printAddress
addressType::addressType(string myStreet, string myCity,
string myState, int myZIP)
{
setStreet(myStreet);
setCity(myCity);
setState(myState);
setZIP(myZIP);
} // end constructor addressType
In: Computer Science
You must write the following methods:
use python 3.7
In: Computer Science
In: Computer Science
Correct all errors in the provided script. Remember that some errors are fatal (result in an error message) while others simply cause the program to produce incorrect results.
You can assume that you have fixed all errors when the checker passes all tests.
%***************************************************************************************
%It is recommended that you debug this program offline and submit only once you have corrected the errors
%***************************************************************************************
%%
%These 3 loops all calculate the sum of the integers from 1 through 1000
for number = 1:1000
total = total + number;
end
fprintf('The sum of the numbers from 1 through 1000 is %i\n', total);
k=0;
theTotal = 0;
while k <1000
theTotal = theTotal + k;
end
fprintf('The sum of the numbers from 1 through 1000 is %i\n', theTotal);
theTotal_2 = 0;
while k >1000
theTotal_2 = theTotal_2 + k;
k = k-1;
end
fprintf('The sum of the numbers from 1 through 1000 is %i\n', theTotal);
%%
%These structures all do the same thing - find the roots of a quadratic,
%and print out the real roots, if any
a = 1;
b = 3;
c = 2;
discriminant = b^2 - 4ac;
if discriminant > 0
root1 = (-b+sqrt(b^2 - 4*a*c))/(2*a);
root2 = (-b-sqrt(b^2 - 4*a*c))/(2*a);
fprintf('The roots are %f and %f\n', root1, root2);
elseif discriminant == 0
root1 = -b/(2*a);
root2 = NaN;
fprintf('The root is %f and %f\n', root1);
else
fprintf('There are no real roots\n');
end
aa = 1;
bb = -8;
cc = 16;
discriminant = bb^2 - 4*aa*cc;
switch discriminant
case discriminant>0
root3 = (-bb+sqrt(bb^2 - 4*aa*cc))/(2*aa);
root4 = (-bb-sqrt(bb^2 - 4*aa*cc))/(2*aa);
fprintf('The roots are %f and %f\n', root3, root4);
case discriminant == 0
root3 = -b/(2*a);
root4 = NaN;
fprintf('The root is %f\n', root3);
otherwise
fprintf('There are no real roots\n');
end
%%
%This program calculates and plots the Fibonacci numbers that are less than
%100
fibonacciNumber=[1, 1];
%first time through the loop, calculating the 3rd Fibonacci number
index = 3;
while fibonacciNumber < 100
fibonacciNumber(end+1) = fibonacciNumber(end) + fibonacciNumber(end-1);
index = index + 1;
end
try
assert(sum(fibonacciNumber>=100)==0)
%The following lines will only be executed if the assertion passes
fprintf('There are %i Fibonacci numbers that are less than 100;', length(fibonacciNumber));
fprintf('They are: \n')
fprintf('%i\n', fibonacciNumber);
plot(1:index, fibonacciNumber)
catch ME
switch ME.identifier
case 'MATLAB:assertion:failed'
disp('Incorrect set of Fibonnaci numbers.')
case 'MATLAB:samelen'
disp('error in plot - vectors not the same length')
otherwise
disp('Something is wrong with the Fibonacci number code')
end
end
%%
%This program calls the user-defined function, GPA() to calculate a
%student's grade point average
Grades = 'ABACAABBDAC';
Credits = [43454453324];
Name = "Joe";
GPAValue = gradePointAverage(grades, credits);
fprintf('%s''s GPA is %d\n', GPAValue);
function [ gradePointAverage] = GPA(letterGrades, numCredits )
%UNTITLED3 Summary of this function goes here
% Detailed explanation goes here
qualityPoints = (letterGrades=='A')*4 + (letterGrades=='B')*3 + (letterGrades=='C')*2 + (letterGrades=='D')*1;
totalPoints = sum(qualityPoints.*credits);
gradePointAverage = totalPoints/sum(credits);
end
In: Computer Science
Write in Java
The Vegetable class should have the usual constructors (default and parameterized), get (accessor) and set (mutator) methods for each attribute, and a toString method
Child classes should call parent methods whenever possible to minimize code duplication.
The driver program must test all the methods in the Vegetable class, and show that the new methods added to the Plant class can be called by each of the child classes. Include comments in your output to describe what you are testing, for example System.out.println(“testing Plant toString, accessor and mutator”);. Print out some blank lines in the output to make it easier to read and understand what is being output.
public class Plant {
private String name;
private String lifespan;
public Plant(){
name = "no name";
lifespan = "do not know";
}
public Plant(String newName, String newlife)
{
name = newName;
lifespan = newlife;
}
public String getName()
{
return name;
}
public String getlife()
{
return lifespan;
}
public void setName(String newName)
{
name = newName;
}
public void setLifeSpan(String newlife)
{
lifespan = newlife;
}
public void set(String newName, String newlife)
{
name = newName;
lifespan = newlife;
}
public String toString()
{
return "Name:"+name+"\nLifeSpan:"+lifespan;
}
}
In: Computer Science
What is Link State Routing? What are its advantages and disadvantages?
In: Computer Science
Please use the python 3.7 for this assigments
Q1 Write a program that accepts the lengths of three sides of a triangle as inputs. The program output should indicate whether or not the triangle is an equilateral triangle.
Q2 Write a program that accepts the lengths of three sides of a triangle as inputs. The program output should indicate whether or not the triangle is a right triangle. Recall from the Pythagorean theorem that in a right triangle, the square of one side equals the sum of the squares of the other two sides.
[FIGURE 3.5] The semantics of a while loop The following example is a short script that prompts the user for a series of numbers, computes their sum, and outputs the result. Instead of forcing the user to enter a definite number of values, the program stops the input process when the user simply presses the return or enter key. The program recognizes this value as the empty string. We first present a rough draft in the form of a pseudocode algorithm: set the sum to 0.0 input a string while the string is not the empty string convert the string to a float add the float to the sum input a string print the sum Note that there are two input statements, one just before the loop header and one at the bottom of the loop body. The first input statement initializes a variable to a value that the loop condition can test. This variable is also called the loop control variable. The second input statement obtains all of the other input val- ues, including one that will terminate the loop. Note also that the input must be received as a string, not a number, so the program can test for an empty string. If the string is not empty, we assume that it represents a number, and we convert it.
Q3 Modify the guessing-game program of Section 3.5 so that the user thinks of a number that the computer must guess. The computer must make no more than the minimum number of guesses.
In: Computer Science
Introduction:
In this project you will create a generic linked list using
Java Generics.
Description:
Create a generic class called GenLinkedList. GenLinkedList will use nodes
that store a value of the generic type to store its contents.
It should have the following methods. The methods should
all operate on the object making the call (none are static).
Perform checking of the parameters and throw exceptions where
appropriate.
The linked list should be singly-linked.
It should not use sentinel nodes (empty header and tail nodes).
You should strive for an efficient implementation of each method.
7 points each (a-h)
a. addFront
receives an item to add as a parameter, and adds to the front of the list.
b. addEnd
receives an item to add as a parameter, and adds to the end of the list.
c. removeFront
removes a node from the front of the list.
d. removeEnd
removes a node from the end of the list.
e. set
receives a position and item as parameters, sets the element at this
position, provided it is within the current size
f. get
receives a position as a parameter, returns the item at this position,
provided it is within the current size
g. swap
receives two index positions as parameters, and swaps the nodes at
these positions, provided both positions are within the current size
h. shift
receives an integer as a parameter, and shifts the list forward or
backward this number of nodes, provided it is within the current size
11 points each (i-l)
i. removeMatching
receives a value of the generic type as a parameter and removes all
occurrences of this value from the list.
j. erase
receives an index position and number of elements as parameters, and
removes elements beginning at the index position for the number of
elements specified, provided the index position is within the size
and together with the number of elements does not exceed the size
k. insertList
receives a generic List (a Java List) and an index position as parameters,
and copies each value of the passed list into the current list starting
at the index position, provided the index position does not exceed the size.
For example, if list has a,b,c and another list having 1,2,3 is inserted at
position 2, the list becomes a,b,1,2,3,c
l. main
add code to the main method to demonstrate each of your methods
Submit to eLearning:
GenLinkedList.javaIn: Computer Science
Write a program that will calculate the cost of installing fiber optic cable at a cost of .87 per ft for a company. Your program should display the company name and the total cost.
In: Computer Science
In no more than half a page, explain and discuss the phase transition phenomenon in random Random 3-SAT. Note: This requires some research. Marks will depend on the quality of presentation, and the depth and breadth of the explanation?
In: Computer Science
You are going to set up a small shopping system, where you are going to implement a "shopping bag" subject to the following specifications:
Make sure your code is well documented. Use the methods that are available in the Bag class.
Source code for Assignment #
/**
An interface that describes the operations of a bag of objects.
@author Frank M. Carrano
@author Timothy M. Henry
@version 4.1
*/
public interface BagInterface<T>
{
/** Gets the current number of entries in this bag.
@return The integer number of entries currently in the bag. */
public int getCurrentSize();
/** Sees whether this bag is empty.
@return True if the bag is empty, or false if not. */
public boolean isEmpty();
/** Adds a new entry to this bag.
@param newEntry The object to be added as a new entry.
@return True if the addition is successful, or false if not. */
public boolean add(T newEntry);
/** Removes one unspecified entry from this bag, if possible.
@return Either the removed entry, if the removal.
was successful, or null. */
public T remove();
/** Removes one occurrence of a given entry from this bag.
@param anEntry The entry to be removed.
@return True if the removal was successful, or false if not. */
public boolean remove(T anEntry);
/** Removes all entries from this bag. */
public void clear();
/** Counts the number of times a given entry appears in this bag.
@param anEntry The entry to be counted.
@return The number of times anEntry appears in the bag. */
public int getFrequencyOf(T anEntry);
/** Tests whether this bag contains a given entry.
@param anEntry The entry to locate.
@return True if the bag contains anEntry, or false if not. */
public boolean contains(T anEntry);
/** Retrieves all entries that are in this bag.
@return A newly allocated array of all the entries in the bag.
Note: If the bag is empty, the returned array is empty. */
public T[] toArray();
// public <T> T[] toArray(); // Alternate
// public Object[] toArray(); // Alternate
/** Creates a new bag that combines the contents of this bag
and anotherBag.
@param anotherBag The bag that is to be added.
@return A combined bag. */
// public BagInterface<T> union(BagInterface<T> anotherBag);
/** Creates a new bag that contains those objects that occur
in both this bag and anotherBag.
@param anotherBag The bag that is to be compared.
@return A combined bag. */
// public BagInterface<T> intersection(BagInterface<T> anotherBag);
/** Creates a new bag of objects that would be left in this bag
after removing those that also occur in anotherBag.
@param anotherBag The bag that is to be removed.
@return A combined bag. */
// public BagInterface<T> difference(BagInterface<T> anotherBag);
} // end BagInterface
Bag Class
public final class LinkedBag<T> implements BagInterface<T>
{
private Node firstNode; // Reference to first node
private int numberOfEntries;
public LinkedBag()
{
firstNode = null;
numberOfEntries = 0;
} // end default constructor
/** Sees whether this bag is empty.
@return True if this bag is empty, or false if not. */
public boolean isEmpty()
{
return numberOfEntries == 0;
} // end isEmpty
/** Gets the number of entries currently in this bag.
@return The integer number of entries currently in this bag. */
public int getCurrentSize()
{
return numberOfEntries;
} // end getCurrentSize
/** Adds a new entry to this bag.
@param newEntry The object to be added as a new entry
@return True if the addition is successful, or false if not. */
public boolean add(T newEntry) // OutOfMemoryError possible
{
// Add to beginning of chain:
Node newNode = new Node(newEntry);
newNode.next = firstNode; // Make new node reference rest of chain
// (firstNode is null if chain is empty)
firstNode = newNode; // New node is at beginning of chain
numberOfEntries++;
return true;
} // end add
/** Retrieves all entries that are in this bag.
@return A newly allocated array of all the entries in this bag. */
public T[] toArray()
{
// The cast is safe because the new array contains null entries
@SuppressWarnings("unchecked")
T[] result = (T[])new Object[numberOfEntries]; // Unchecked cast
int index = 0;
Node currentNode = firstNode;
while ((index < numberOfEntries) && (currentNode != null))
{
result[index] = currentNode.data;
index++;
currentNode = currentNode.next;
} // end while
return result;
} // end toArray
/** Counts the number of times a given entry appears in this bag.
@param anEntry The entry to be counted.
@return The number of times anEntry appears in this bag. */
public int getFrequencyOf(T anEntry)
{
int frequency = 0;
int counter = 0;
Node currentNode = firstNode;
while ((counter < numberOfEntries) && (currentNode != null))
{
if (anEntry.equals(currentNode.data))
{
frequency++;
} // end if
counter++;
currentNode = currentNode.next;
} // end while
return frequency;
} // end getFrequencyOf
/** Tests whether this bag contains a given entry.
@param anEntry The entry to locate.
@return True if the bag contains anEntry, or false otherwise. */
public boolean contains(T anEntry)
{
boolean found = false;
Node currentNode = firstNode;
while (!found && (currentNode != null))
{
if (anEntry.equals(currentNode.data))
found = true;
else
currentNode = currentNode.next;
} // end while
return found;
} // end contains
// Locates a given entry within this bag.
// Returns a reference to the node containing the entry, if located,
// or null otherwise.
private Node getReferenceTo(T anEntry)
{
boolean found = false;
Node currentNode = firstNode;
while (!found && (currentNode != null))
{
if (anEntry.equals(currentNode.data))
found = true;
else
currentNode = currentNode.next;
} // end while
return currentNode;
} // end getReferenceTo
/** Removes all entries from this bag. */
public void clear()
{
while (!isEmpty())
remove();
} // end clear
/** Removes one unspecified entry from this bag, if possible.
@return Either the removed entry, if the removal
was successful, or null. */
public T remove()
{
T result = null;
if (firstNode != null)
{
result = firstNode.data;
firstNode = firstNode.next; // Remove first node from chain
numberOfEntries--;
} // end if
return result;
} // end remove
/** Removes one occurrence of a given entry from this bag, if possible.
@param anEntry The entry to be removed.
@return True if the removal was successful, or false otherwise. */
public boolean remove(T anEntry)
{
boolean result = false;
Node nodeN = getReferenceTo(anEntry);
if (nodeN != null)
{
nodeN.data = firstNode.data; // Replace located entry with entry in first node
firstNode = firstNode.next; // Remove first node
numberOfEntries--;
result = true;
} // end if
return result;
} // end remove
private class Node
{
private T data; // Entry in bag
private Node next; // Link to next node
private Node(T dataPortion)
{
this(dataPortion, null);
} // end constructor
private Node(T dataPortion, Node nextNode)
{
data = dataPortion;
next = nextNode;
} // end constructor
} // end Node
} // end LinkedBagIn: Computer Science