Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
11th Edition
ISBN: 9780134670942
Author: Y. Daniel Liang
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 21.2, Problem 21.2.8CP
Program Plan Intro
Program:
// Java code for adding elements in Set
//import util package
import java.util.*;
//class definition
public class Set_Example {
// main method
public static void main(String[] args) {
// create a new empty LinkedHashSet
Set<String> set = new LinkedHashSet<>();
// add element ABC into the set
set.add("ABC");
// add element and into the set
set.add("ABD");
// print elements present in the set
System.out.println(set);
}
}
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
#include <iostream>
using namespace std;
int BinSearch(int arr[],int beg, int end, int key){ if(beg > end){ return -1; } else{ int mid = beg + (end - beg) / 2; if(arr[mid] == key){ return mid; } else if(key < arr[mid]){ return BinSearch(arr,beg,mid-1,key); } else{ return BinSearch(arr,mid+1,end,key); } }}
int main(){ int arr[] = {1,2,3,4,5,6,7,8}; int n = sizeof(arr)/sizeof(arr[0]); int key; cout << "Enter the key to be searched: " << endl; cin >> key; int res = BinSearch(arr,0,n-1,key); (res == -1) ? cout << "Element is not present in array" : cout << "Element is present at index " << res;
return 0;}Q: Remove Function in above algorithm
C++ ProgrammingActivity: Deque Linked List
Explain the flow of the code not necessarily every line, as long as you explain what the important parts of the code do. The code is already correct, just explain the flow.
#include "deque.h"
#include "linkedlist.h"
#include <iostream>
using namespace std;
class DLLDeque : public Deque {
DoublyLinkedList* list;
public:
DLLDeque() {
list = new DoublyLinkedList();
}
void addFirst(int e) {
list->addAt(e,1);
}
void addLast(int e) {
list->addAt(e,size()+1);
}
int removeFirst() {
return list->removeAt(1);
}
int removeLast() {
return list->removeAt(size());
}
int size(){
return list->size();
}
bool isEmpty() {
return list->isEmpty();
}
// OPTIONAL: a helper method to help you debug
void print() {…
#include <stdio.h>#include <stdlib.h>#include <time.h>
struct treeNode { struct treeNode* leftPtr; int data; struct treeNode* rightPtr;};
typedef struct treeNode TreeNode;typedef TreeNode* TreeNodePtr;
void insertNode(TreeNodePtr* treePtr, int value);void inOrder(TreeNodePtr treePtr);void preOrder(TreeNodePtr treePtr);void postOrder(TreeNodePtr treePtr);
int main(void) { TreeNodePtr rootPtr = NULL;
srand(time(NULL)); puts("The numbers being placed in the tree are:");
for (unsigned int i = 1; i <= 10; ++i) { int item = rand() % 15; printf("%3d", item); insertNode(&rootPtr, item); }
puts("\n\nThe preOrder traversal is: "); preOrder(rootPtr);
puts("\n\nThe inOrder traversal is: "); inOrder(rootPtr);
puts("\n\nThe postOrder traversal is: "); postOrder(rootPtr);}
void insertNode(TreeNodePtr* treePtr, int value) { if (*treePtr == NULL) { *treePtr = malloc(sizeof(TreeNode));
if…
Chapter 21 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Ch. 21.2 - Prob. 21.2.1CPCh. 21.2 - Prob. 21.2.2CPCh. 21.2 - Prob. 21.2.3CPCh. 21.2 - Prob. 21.2.4CPCh. 21.2 - Prob. 21.2.5CPCh. 21.2 - Suppose set1 is a set that contains the strings...Ch. 21.2 - Prob. 21.2.7CPCh. 21.2 - Prob. 21.2.8CPCh. 21.2 - What will the output be if lines 67 in Listing...Ch. 21.2 - Prob. 21.2.10CP
Ch. 21.3 - Prob. 21.3.1CPCh. 21.3 - Suppose you need to write a program that stores...Ch. 21.3 - Suppose you need to write a program that stores...Ch. 21.3 - Suppose you need to write a program that stores a...Ch. 21.3 - Prob. 21.3.5CPCh. 21.3 - Prob. 21.3.6CPCh. 21.4 - Prob. 21.4.1CPCh. 21.4 - Prob. 21.4.2CPCh. 21.5 - Prob. 21.5.1CPCh. 21.5 - Prob. 21.5.2CPCh. 21.5 - Prob. 21.5.3CPCh. 21.6 - Prob. 21.6.1CPCh. 21.6 - Prob. 21.6.2CPCh. 21.6 - Prob. 21.6.3CPCh. 21.6 - Prob. 21.6.4CPCh. 21.7 - Prob. 21.7.1CPCh. 21.7 - Prob. 21.7.2CPCh. 21 - Prob. 21.1PECh. 21 - (Display nonduplicate words in ascending order)...Ch. 21 - Prob. 21.3PECh. 21 - (Count consonants and vowels) Write a program that...Ch. 21 - Prob. 21.6PECh. 21 - (Revise Listing 21.9, CountOccurrenceOfWords.java)...Ch. 21 - Prob. 21.8PECh. 21 - Prob. 21.9PE
Knowledge Booster
Similar questions
- #include <stdio.h>#include <stdlib.h>#include <time.h> struct treeNode { struct treeNode *leftPtr; int data; struct treeNode *rightPtr;}; typedef struct treeNode TreeNode;typedef TreeNode *TreeNodePtr; void insertNode(TreeNodePtr *treePtr, int value);void inOrder(TreeNodePtr treePtr);void preOrder(TreeNodePtr treePtr);void postOrder(TreeNodePtr treePtr); int main(void) { TreeNodePtr rootPtr = NULL; srand(time(NULL)); puts("The numbers being placed in the tree are:"); for (unsigned int i = 1; i <= 10; ++i) { int item = rand() % 15; printf("%3d", item); insertNode(&rootPtr, item); } puts("\n\nThe preOrder traversal is: "); preOrder(rootPtr); puts("\n\nThe inOrder traversal is: "); inOrder(rootPtr); puts("\n\nThe postOrder traversal is: "); postOrder(rootPtr);} void insertNode(TreeNodePtr *treePtr, int value) { if (*treePtr == NULL) { *treePtr = malloc(sizeof(TreeNode)); if (*treePtr != NULL) { (*treePtr)->data = value;…arrow_forwarddef cartesianproduct(lst): """Takes a list of sets/frozensets and computes their Cartesian product""" cartesianproduct: This function should accept a list of one or more sets or frozensets (you can convert between them using set(fro_st) and frozenset(st)). Its output is a set or frozenset encoding the cartesian product; thus a list of two sets [{0,1}, {1,2}] could give back {(0,1),(0,2),(1,1),(1,2)}. In general, an input list of length N will yield a set of tuples of length N each.arrow_forwardLook at the code.arrow_forward
- #include<iostream> #include<cstdlib> #include<string> #include<cstdio> using namespace std; const int TABLE_SIZE = 128; /* * HashEntry Class Declaration */ class HashEntry { public: int key; int value; HashEntry(int key, int value) { this->key = key; this->value = value; } }; /* * HashMap Class Declaration */ class HashMap { private: HashEntry **table; public: HashMap() { table = new HashEntry * [TABLE_SIZE]; for (int i = 0; i< TABLE_SIZE; i++) { table[i] = NULL; } } /* * Hash Function */ int HashFunc(int key) { return key % TABLE_SIZE; } /* * Insert Element at a key */ void Insert(int key, int value) { int hash = HashFunc(key); while (table[hash] != NULL && table[hash]->key != key)…arrow_forward#include<iostream> #include<cstdlib> #include<string> #include<cstdio> using namespace std; const int TABLE_SIZE = 128; /* * HashEntry Class Declaration */ class HashEntry { public: int key; int value; HashEntry(int key, int value) { this->key = key; this->value = value; } }; /* * HashMap Class Declaration */ class HashMap { private: HashEntry **table; public: HashMap() { table = new HashEntry * [TABLE_SIZE]; for (int i = 0; i< TABLE_SIZE; i++) { table[i] = NULL; } } /* * Hash Function */ int HashFunc(int key) { return key % TABLE_SIZE; } /* * Insert Element at a key */ void Insert(int key, int value) { int hash = HashFunc(key); while (table[hash] != NULL && table[hash]->key != key)…arrow_forwarddf.Month.replace(({1:'January', 2:'February', 3:'March',4:'April', 5:'May', 6:'June', 7:'July', 8:'August',9:'September',10:'October',11:'November',12:'December'}), inplace=True)df kindly explain what this code do in phytonarrow_forward
- this is my code and the question need to be continued. #include <iostream>using namespace std; class Course{private: string name; string *studentList; int size, capacity=10;public: Course(){ name = "TBD"; size = 0; studentList = new string[capacity]; }Course(string s){ name = s; size = 0; studentList = new string[capacity]; }void setName(string s){ name = s; }getter/accessor for variable name string getName(){ return name; }}; int main(){ Course a, b("Yankee"); cout << a.getName() << endl; a.setName("Mets"); cout << a.getName() << endl; cout << b.getName() << endl; return 0;} this is the Question:: Continue with Team class: a) Copy the previous program to a new file.b) Implement the addMember, removeMember and…arrow_forwardtypedef struct node_t node_t; struct node_t { }; int32_t value; node_t* next; node_t* insert (node_t* list, int32_t v, int32_t* flag); 3) As you may have noticed from MT1, Howie is lazy. He wants you to write the interface for the following implementation of function copy_to_linked_list. He really appreciates your help! /* copy_to_linked_list int32_t copy_to_linked_list (int32_t a[], int32_t size, node_t** list_p) { int32_t flag, i; for (i = 0; i < size; ++i) { *list_p = insert (*list_p, a[i], &flag); if (-1== flag) return -1; } return 0;arrow_forward/* 1- write the removeLast function which removes the last digit from a given number, if the number Int //Start = removeLast 1223 10 //Start = removeLast //Start = removeLast //Start = removeLast 9 //Start = removeLast -58545 // 122 // 1 // 2 // 9 // -58545 23arrow_forward
- int X[10]={2,0,6,11,4,5,9,11,-2,-1); From the code above, what is the value of X[8] ?arrow_forwarddata structures-java language quickly plsarrow_forwardstruct nodeType { int infoData; nodeType * next; }; nodeType *first; … and containing the values(see image) Using a loop to reach the end of the list, write a code segment that deletes all the nodes in the list. Ensure the code performs all memory ‘cleanup’ functions.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education