Introduction to Java Programming and Data Structures: Brief Version (11th Global Edition)
11th Edition
ISBN: 9780134671710
Author: Y. Daniel Liang
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 21.2, Problem 21.2.10CP
Program Plan Intro
Program:
// Java code for adding elements in Set
//import util package
import java.util.*;
//class definition
public class Example_1 {
// main method
public static void main(String[] args)
{
/*Create a new TreeSet and use comparator to compare string length*/
Set<String> set = new TreeSet<>(
Comparator.comparing(String::length));
//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
Not allowed to add variables in brackets next to originIndex
* @return index of the point that is closest to the origin, which is (0, 0) In * case of a tie, return the lowest index */ public int closestToOriginIndex() {
//give the output of the following program and draw the link list.
struct node{ int info; struct node *link;};typedef struct node *nodePTR;void insort(nodePTR*,struct Info);nodePTR getnode();int main(void){nodePTR p=NULL,head=NULL,save;inti;
for(i=0;i<3;i++){ insort (&head,i+5);}save=head;do{ printf("%d",save->info); save=save->link;}while(save!=NULL);
return0;}nodePTR getnode(){nodePTR q;q=(nodePTR)malloc(sizeof(struct node));return q;}void insort(NODEPTR *head , int x){ NODEPTR p,q,r; q=NULL; for(p=*head; p!=NULL &&x>p->info; p=p->link) q=p; if(q=NULL) { p=getnode(); p->info=x; p->link=head; head=p; }else{ r=getnode(); q->link=r; r->info=x; r->link=p; }}
using namespace std;
class SinglyLinkedListNode {
// INSERT YOUR CODE HERE
};
class SinglyLinkedList {
public:
SinglyLinkedListNode *head;
SinglyLinkedListNode *tail;
SinglyLinkedList() {
this->head = nullptr;
this->tail = nullptr;
}
voidinsert_node(intnode_data) {
// INSERT YOUR CODE HERE
}
};
void free_singly_linked_list(SinglyLinkedListNode* node) {
// INSERT YOUR CODE HERE
}
// Complete the has_cycle function below.
/*
* For your reference:
*
* SinglyLinkedListNode {
* int data;
* SinglyLinkedListNode* next;
* };
*
*/
bool has_cycle(SinglyLinkedListNode* head) {
SinglyLinkedListNode* temp = head;
bool isCycle = false;
while (temp != nullptr)
{
// INSERT YOUR CODE HERE
}
}
int main()
{
// INSERT YOUR CODE HERE TO TEST YOUR CODE
return0;
}
Chapter 21 Solutions
Introduction to Java Programming and Data Structures: Brief Version (11th Global 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
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- using namespace std; class SinglyLinkedListNode { // INSERT YOUR CODE HERE }; class SinglyLinkedList { public: SinglyLinkedListNode *head; SinglyLinkedListNode *tail; SinglyLinkedList() { this->head = nullptr; this->tail = nullptr; } voidinsert_node(intnode_data) { // INSERT YOUR CODE HERE } }; void free_singly_linked_list(SinglyLinkedListNode* node) { // INSERT YOUR CODE HERE } // Complete the has_cycle function below. /* * For your reference: * * SinglyLinkedListNode { * int data; * SinglyLinkedListNode* next; * }; * */ bool has_cycle(SinglyLinkedListNode* head) { SinglyLinkedListNode* temp = head; bool isCycle = false; while (temp != nullptr) { // INSERT YOUR CODE HERE } } int main() { // INSERT YOUR CODE HERE TO TEST YOUR CODE return0; }arrow_forwardWrite a display function and delete function in the following code: Declare the libraries Declare the struct Node void create (int A[], int n) { int i; struct Node *t, *last; first = (struct Node *)malloc(sizeof(struct Node)); first->data=A[0]; first->next=NULL; last=first; for(i=1;i<n;i++) { t=(struct Node *)malloc(sizeof(struct Node)); t->data=A[i]; t->next=NULL; last->next=t; last=t; } } Write the Delete Function Write the display function int main() { int A[]={10,20,30,40,50}; create(A,5); Delete(first,4); Display(first); return 0; }arrow_forward#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 algorithmarrow_forward
- Doctor -signature:String -doctorID:int - medicine:Arraylist +Doctor(signature:String,doctorID:int) +PrescribeMedicine():void + salary () +checkRecords():void Medicine Pharmacist -medName:String -startTime:int -dosage :int -endTime:int -date_prescribed:int - medicine:Arraylist +Medicine(medName:String,-dosage :int,date_prescribed:int) +Pharmacist (startTime:int,endTime:int) +checkForConflict():double +confirm_prescription():String +getStartTime():int +getEndTime():int +setStartTime(time:int):void +setEndTime(time1:int).voidarrow_forwardvoid listEmployees (void) { for (int i=0; i 10000. Make a guess about why the comparison function takes 2 struct Employee parameters (as opposed to struct Employee *) **arrow_forwardin c++ pleasearrow_forward
- Write the set-builder notation of {0,4,16,36,64,100,…}.arrow_forwarddef strPattern(mystr):lenght = len(mystr)mystr1 = ""for i in range(lenght - 1):mystr1 = mystr1 + mystr[i].upper() + str(i + 1)if lenght == 0:return mystr1return mystr1 + mystr[-1].upper()s = input("enter a word: ")print(strPattern(s)) s = input("enter a word: ") EOFError: EOF when reading a line HOW CAN I FIX THIS QUESTION?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
- CODE in RACKET ONLY flatten-1: takes a list and "flattens" any nested lists by one level. E.g., > (flatten-1 '(a (b c) d)) '(a b c d) > (flatten-1 '((a) (b ((c) (d))) ((e f)))) '(a b ((c) (d)) (e f)) > (flatten-1 (flatten-1 '((a) (b ((c) (d))) ((e f))))) '(a b (c) (d) e f) > (flatten-1 (flatten-1 (flatten-1 '((a) (b ((c) (d))) ((e f)))))) '(a b c d e f)arrow_forward#include <stdio.h> int arrC[10] = {0}; int bSearch(int arr[], int l, int h, int key); int *joinArray(int arrA[], int arrB[]) { int j = 0; if ((arrB[0] + arrB[4]) % 5 == 0) { arrB[0] = 0; arrB[4] = 0; } for (int i = 0; i < 5; i++) { arrC[j++] = arrA[i]; if (arrB[i] == 0 || (bSearch(arrA, 0, 5, arrB[i]) != -1)) { continue; } else arrC[j++] = arrB[i]; } for (int i = 0; i < j; i++) { int temp; for (int k = i + 1; k < j; k++) { if (arrC[i] > arrC[k]) { temp = arrC[i]; arrC[i] = arrC[k]; arrC[k] = temp; } } } for (int i = 0; i < j; i++) { printf("%d ", arrC[i]); } return arrC; } int bSearch(int arr[], int l, int h, int key) { if (h >= l) { int mid = l + (h - l) / 2; if…arrow_forwarddata structures-java language quickly plsarrow_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