SlideShare a Scribd company logo
1 of 6
Download to read offline
Hindu-Arabic decimal numbers use the digits 0, 1, 2, 3, 4, 5, 6, 7, 8, 9. We form decimal numbers
creating strings with these digits, for example 102, 88, 12.
Recall that, for example, 12 is 1x10
1
+ 2x10
0
Binary numbers use only 0 and 1. We can create numbers by creating strings with 0s and 1s.
Example:
1 is expressed as 1 (1x2
0
)
2 is expressed as 10 (1x2
1
+ 0x2
0
)
3 is expressed as 11 (1x2
1
+ 1x2
0
)
The first 5 integers are 1, 10, 11, 100, 101
The first 8 integers are expressed as 1, 10, 11, 100, 101, 110, 111, 1000
The first 16 integers are expressed as 1, 10, 11, 100, 101, 110, 111, 1000, 1001, 1010, 1011,
1100, 1101, 1110, 1111, 10000
Write a non-member method binaryNumberSequence(int n) that produces the sequence of the
first N integers.
The method receives as parameter a number n, and returns a Queue<String> with n strings
representing the first n integers converted to binary.
The elements in the queue come in the increasing sequence order of the number. For example, a
call to binaryNumberSequence(5) returns Q = {1, 10, 11, 100, 101}.
You MUST create and store the binary number using division, mods, and a queue.
LINKEDSTACKED IMPLEMENTATION
public class LinkedStack<E> implements Stack<E> {
@SuppressWarnings("hiding")
private class Node<E> {
private E element;
private Node<E> next;
public Node(E elm, Node<E> next) {
this.element = elm;
this.next = next;
}
public Node(E elm) {
this(elm, null);
}
public Node() {
this(null, null);
}
public E getElement() {
return element;
}
public void setElement(E element) {
this.element = element;
}
public Node<E> getNext() {
return next;
}
public void setNext(Node<E> next) {
this.next = next;
}
public void clear() {
this.element = null;
this.next = null;
}
} //End of Node Class
private Node<E> header;
private int currentSize;
public LinkedStack() {
this.header = new Node<>();
this.currentSize = 0;
}
@Override
public void push(E newEntry) {
if(newEntry == null)
throw new IllegalArgumentException("Parameter cannot be null");
Node<E> newNode = new Node<>(newEntry, header.getNext());
header.setNext(newNode);
currentSize++;
}
@Override
public E pop() {
if(isEmpty())
throw new EmptyStackException();
E elm = header.getNext().getElement();
Node<E> rmNode = header.getNext();
header.setNext(rmNode.getNext());
rmNode.clear();
rmNode = null;
currentSize--;
return elm;
}
@Override
public E top() {
if(isEmpty())
throw new EmptyStackException();
return header.getNext().getElement();
}
@Override
public boolean isEmpty() {
return size() == 0;
}
@Override
public int size() {
return currentSize;
}
@Override
public void clear() {
while(!isEmpty())
pop();
}
}
BROWSER CLASS
@Test
public void test1() {
String[] input = {"Google", "Facebook", "Instagram", "<", ">"};
String[] expected = {"Google", "Facebook", "Instagram", "Facebook", "Instagram"};
assertArrayEquals(expected, p.browserHistory(input));
}
@Test
public void test2() {
String[] input = {"Google", "Facebook", "Instagram", "<", "<", ">", "Wikipedia", "Reddit", "<", "<",
">"};
String[] expected = {"Google", "Facebook", "Instagram", "Facebook", "Google", "Facebook",
"Wikipedia", "Reddit", "Wikipedia", "Facebook", "Wikipedia"};
assertArrayEquals(expected, p.browserHistory(input));
}
@Test
public void test3() {
String[] input = {"Google", "Facebook", "<", "<"};
String[] expected = {"Google", "Facebook", "Google"};
assertArrayEquals(expected, p.browserHistory(input));
}
package lab5.problems;
import java.util.ArrayList;
import java.util.List;
import lab5.util.dataStructures.LinkedStack;
import lab5.util.interfaces.Stack;
public class BrowserHistoryProblem {
/**
* TODO EXERCISE 1:
*
* In your Internet browser (e.g. Google Chrome), you can use the "back" and "forward" arrows
* to navigate through your browsing history.
*
* Implement a non-member method called browserHistory(String[] clicks) that takes
* a list of strings called clicks containing a mix of pages visited and back/forward arrow clicks,
* and returns a list of the pages visited in order.
*
* It may be helpful to open a new Google Chrome tab and experiment with using the backward
and forward buttons.
*
* Example:
* Assume clicks = {"Google", "Facebook", "Instagram", "<", ">"},
* then a call to browserHistory(clicks) returns {"Google", "Facebook", "Instagram", "Facebook",
"Instagram"}
* because the user went backward to Facebook, then forward to Instagram.
*
* Here are some additional edge cases to consider:
*
* 1) The user may hit the back or forward buttons multiple times in a row.
* 2) If the user tries to click the "back" or "forward" arrow even though
* there is nowhere to go / it is greyed out, keep them on the same page without reloading the
page.
* 3) The user might refresh the page / visit the same page multiple times in a row.
* Count these as a single visit.
* 4) The user might visit the same page multiple times, but not necessarily in a row. Consider
these distinct.
*
* Hint: Store the result and its values using an ArrayList<String> (import from java.util) as you
* make your solution and return them as an array of strings using result.toArray(new
String[result.size()])
*
* WARNING: You MUST use a stack, implementations that use indices (or pointers) will receive
ZERO credit.
*
* @param clicks - Array of strings denoting the web pages and clicks user made in their browser
* @return The Array of strings with clicks made with the forward and back buttons replaced with
* the corresponding page
*/
public String[] browserHistory(String[] clicks) {
/*TODO ADD YOUR CODE HERE*/
return new String[0]; // Dummy Return
}
}

More Related Content

Similar to HinduArabic decimal numbers use the digits 0 1 2 3 4 5.pdf

How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdfHow do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
mail931892
 
I need help implementing a Stack with this java programming assignme.pdf
I need help implementing a Stack with this java programming assignme.pdfI need help implementing a Stack with this java programming assignme.pdf
I need help implementing a Stack with this java programming assignme.pdf
sauravmanwanicp
 
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdfHow do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
mail931892
 
How do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdfHow do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdf
feelinggift
 
File LinkedList.java Defines a doubly-l.pdf
File LinkedList.java Defines a doubly-l.pdfFile LinkedList.java Defines a doubly-l.pdf
File LinkedList.java Defines a doubly-l.pdf
Conint29
 
Copy your completed LinkedList class from Lab 3 into the LinkedList..pdf
Copy your completed LinkedList class from Lab 3 into the LinkedList..pdfCopy your completed LinkedList class from Lab 3 into the LinkedList..pdf
Copy your completed LinkedList class from Lab 3 into the LinkedList..pdf
facevenky
 
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdfLabprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
freddysarabia1
 
how to reuse code
how to reuse codehow to reuse code
how to reuse code
jleed1
 
Help I keep getting the same error when running a code. Below is the.pdf
Help I keep getting the same error when running a code. Below is the.pdfHelp I keep getting the same error when running a code. Below is the.pdf
Help I keep getting the same error when running a code. Below is the.pdf
mail931892
 
How do I fix it in javaLinkedList.java Defines a doubl.pdf
How do I fix it in javaLinkedList.java Defines a doubl.pdfHow do I fix it in javaLinkedList.java Defines a doubl.pdf
How do I fix it in javaLinkedList.java Defines a doubl.pdf
fmac5
 
How do I fix it in LinkedList.javaLinkedList.java Define.pdf
How do I fix it in LinkedList.javaLinkedList.java Define.pdfHow do I fix it in LinkedList.javaLinkedList.java Define.pdf
How do I fix it in LinkedList.javaLinkedList.java Define.pdf
mail931892
 
How do I fix this error - Exception in thread -main- java-lang-NullPoi.pdf
How do I fix this error - Exception in thread -main- java-lang-NullPoi.pdfHow do I fix this error - Exception in thread -main- java-lang-NullPoi.pdf
How do I fix this error - Exception in thread -main- java-lang-NullPoi.pdf
pnaran46
 
Sorted number list implementation with linked listsStep 1 Inspec.pdf
 Sorted number list implementation with linked listsStep 1 Inspec.pdf Sorted number list implementation with linked listsStep 1 Inspec.pdf
Sorted number list implementation with linked listsStep 1 Inspec.pdf
almaniaeyewear
 

Similar to HinduArabic decimal numbers use the digits 0 1 2 3 4 5.pdf (20)

How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdfHow do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
 
First few months with Kotlin - Introduction through android examples
First few months with Kotlin - Introduction through android examplesFirst few months with Kotlin - Introduction through android examples
First few months with Kotlin - Introduction through android examples
 
I need help implementing a Stack with this java programming assignme.pdf
I need help implementing a Stack with this java programming assignme.pdfI need help implementing a Stack with this java programming assignme.pdf
I need help implementing a Stack with this java programming assignme.pdf
 
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdfHow do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
 
131 Lab slides (all in one)
131 Lab slides (all in one)131 Lab slides (all in one)
131 Lab slides (all in one)
 
Java script
Java scriptJava script
Java script
 
How do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdfHow do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdf
 
File LinkedList.java Defines a doubly-l.pdf
File LinkedList.java Defines a doubly-l.pdfFile LinkedList.java Defines a doubly-l.pdf
File LinkedList.java Defines a doubly-l.pdf
 
Copy your completed LinkedList class from Lab 3 into the LinkedList..pdf
Copy your completed LinkedList class from Lab 3 into the LinkedList..pdfCopy your completed LinkedList class from Lab 3 into the LinkedList..pdf
Copy your completed LinkedList class from Lab 3 into the LinkedList..pdf
 
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdfLabprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
 
how to reuse code
how to reuse codehow to reuse code
how to reuse code
 
Help I keep getting the same error when running a code. Below is the.pdf
Help I keep getting the same error when running a code. Below is the.pdfHelp I keep getting the same error when running a code. Below is the.pdf
Help I keep getting the same error when running a code. Below is the.pdf
 
130717666736980000
130717666736980000130717666736980000
130717666736980000
 
Visual Programing basic lectures 7.pptx
Visual Programing basic lectures  7.pptxVisual Programing basic lectures  7.pptx
Visual Programing basic lectures 7.pptx
 
How do I fix it in javaLinkedList.java Defines a doubl.pdf
How do I fix it in javaLinkedList.java Defines a doubl.pdfHow do I fix it in javaLinkedList.java Defines a doubl.pdf
How do I fix it in javaLinkedList.java Defines a doubl.pdf
 
Introduction to python programming
Introduction to python programmingIntroduction to python programming
Introduction to python programming
 
How do I fix it in LinkedList.javaLinkedList.java Define.pdf
How do I fix it in LinkedList.javaLinkedList.java Define.pdfHow do I fix it in LinkedList.javaLinkedList.java Define.pdf
How do I fix it in LinkedList.javaLinkedList.java Define.pdf
 
Functional Programming with Groovy
Functional Programming with GroovyFunctional Programming with Groovy
Functional Programming with Groovy
 
How do I fix this error - Exception in thread -main- java-lang-NullPoi.pdf
How do I fix this error - Exception in thread -main- java-lang-NullPoi.pdfHow do I fix this error - Exception in thread -main- java-lang-NullPoi.pdf
How do I fix this error - Exception in thread -main- java-lang-NullPoi.pdf
 
Sorted number list implementation with linked listsStep 1 Inspec.pdf
 Sorted number list implementation with linked listsStep 1 Inspec.pdf Sorted number list implementation with linked listsStep 1 Inspec.pdf
Sorted number list implementation with linked listsStep 1 Inspec.pdf
 

More from aayushmaany2k14

7 You have just discovered a new fungal species from Yellow.pdf
7 You have just discovered a new fungal species from Yellow.pdf7 You have just discovered a new fungal species from Yellow.pdf
7 You have just discovered a new fungal species from Yellow.pdf
aayushmaany2k14
 
7 Using terms from the key on the right correctly identify.pdf
7 Using terms from the key on the right correctly identify.pdf7 Using terms from the key on the right correctly identify.pdf
7 Using terms from the key on the right correctly identify.pdf
aayushmaany2k14
 

More from aayushmaany2k14 (20)

7 In pea plants round R is dominant to wrinkled r A h.pdf
7 In pea plants round R is dominant to wrinkled r A h.pdf7 In pea plants round R is dominant to wrinkled r A h.pdf
7 In pea plants round R is dominant to wrinkled r A h.pdf
 
7 In cats some are black some are orange and some are ca.pdf
7 In cats some are black some are orange and some are ca.pdf7 In cats some are black some are orange and some are ca.pdf
7 In cats some are black some are orange and some are ca.pdf
 
7 You have just discovered a new fungal species from Yellow.pdf
7 You have just discovered a new fungal species from Yellow.pdf7 You have just discovered a new fungal species from Yellow.pdf
7 You have just discovered a new fungal species from Yellow.pdf
 
7 Write the MIPS code to implement the for loop below Use .pdf
7 Write the MIPS code to implement the for loop below Use .pdf7 Write the MIPS code to implement the for loop below Use .pdf
7 Write the MIPS code to implement the for loop below Use .pdf
 
7 Given the diagram above describe the order of events in .pdf
7 Given the diagram above describe the order of events in .pdf7 Given the diagram above describe the order of events in .pdf
7 Given the diagram above describe the order of events in .pdf
 
7 Ontario Resources a natural energy supplier borrowed 8.pdf
7 Ontario Resources a natural energy supplier borrowed 8.pdf7 Ontario Resources a natural energy supplier borrowed 8.pdf
7 Ontario Resources a natural energy supplier borrowed 8.pdf
 
7 Let XiiZ+1i2path dM263681c0701839752119c34.pdf
7 Let XiiZ+1i2path dM263681c0701839752119c34.pdf7 Let XiiZ+1i2path dM263681c0701839752119c34.pdf
7 Let XiiZ+1i2path dM263681c0701839752119c34.pdf
 
7 Essay What is the difference between efficiency and equ.pdf
7 Essay What is the difference between efficiency and equ.pdf7 Essay What is the difference between efficiency and equ.pdf
7 Essay What is the difference between efficiency and equ.pdf
 
7 What is most true about the following B2B promotional too.pdf
7 What is most true about the following B2B promotional too.pdf7 What is most true about the following B2B promotional too.pdf
7 What is most true about the following B2B promotional too.pdf
 
7 What do foxes and birds have in common a They are both .pdf
7 What do foxes and birds have in common a They are both .pdf7 What do foxes and birds have in common a They are both .pdf
7 What do foxes and birds have in common a They are both .pdf
 
7 Using terms from the key on the right correctly identify.pdf
7 Using terms from the key on the right correctly identify.pdf7 Using terms from the key on the right correctly identify.pdf
7 Using terms from the key on the right correctly identify.pdf
 
7 Using node 1 as the root perform a BFS for node 6 Detai.pdf
7 Using node 1 as the root perform a BFS for node 6 Detai.pdf7 Using node 1 as the root perform a BFS for node 6 Detai.pdf
7 Using node 1 as the root perform a BFS for node 6 Detai.pdf
 
8 The residents of Elk Meadows and Valley View are experien.pdf
8 The residents of Elk Meadows and Valley View are experien.pdf8 The residents of Elk Meadows and Valley View are experien.pdf
8 The residents of Elk Meadows and Valley View are experien.pdf
 
8 What would be the most possible interaction between the s.pdf
8 What would be the most possible interaction between the s.pdf8 What would be the most possible interaction between the s.pdf
8 What would be the most possible interaction between the s.pdf
 
8 A unique structure in vertebrate embryos is the somite S.pdf
8 A unique structure in vertebrate embryos is the somite S.pdf8 A unique structure in vertebrate embryos is the somite S.pdf
8 A unique structure in vertebrate embryos is the somite S.pdf
 
7 Kate has a utility function Uxy4xpath dM95702c.pdf
7 Kate has a utility function Uxy4xpath dM95702c.pdf7 Kate has a utility function Uxy4xpath dM95702c.pdf
7 Kate has a utility function Uxy4xpath dM95702c.pdf
 
8 Protein synthesis begins when in the nucleus of each cell.pdf
8 Protein synthesis begins when in the nucleus of each cell.pdf8 Protein synthesis begins when in the nucleus of each cell.pdf
8 Protein synthesis begins when in the nucleus of each cell.pdf
 
729 David is going to purchase two stocks to form the initi.pdf
729 David is going to purchase two stocks to form the initi.pdf729 David is going to purchase two stocks to form the initi.pdf
729 David is going to purchase two stocks to form the initi.pdf
 
8 IPOsinitial public offerings of stockcreate billions of.pdf
8 IPOsinitial public offerings of stockcreate billions of.pdf8 IPOsinitial public offerings of stockcreate billions of.pdf
8 IPOsinitial public offerings of stockcreate billions of.pdf
 
8 Agreement and disagreement among economists Suppose that .pdf
8 Agreement and disagreement among economists Suppose that .pdf8 Agreement and disagreement among economists Suppose that .pdf
8 Agreement and disagreement among economists Suppose that .pdf
 

Recently uploaded

Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Recently uploaded (20)

Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 

HinduArabic decimal numbers use the digits 0 1 2 3 4 5.pdf

  • 1. Hindu-Arabic decimal numbers use the digits 0, 1, 2, 3, 4, 5, 6, 7, 8, 9. We form decimal numbers creating strings with these digits, for example 102, 88, 12. Recall that, for example, 12 is 1x10 1 + 2x10 0 Binary numbers use only 0 and 1. We can create numbers by creating strings with 0s and 1s. Example: 1 is expressed as 1 (1x2 0 ) 2 is expressed as 10 (1x2 1 + 0x2 0 ) 3 is expressed as 11 (1x2 1 + 1x2 0 ) The first 5 integers are 1, 10, 11, 100, 101 The first 8 integers are expressed as 1, 10, 11, 100, 101, 110, 111, 1000 The first 16 integers are expressed as 1, 10, 11, 100, 101, 110, 111, 1000, 1001, 1010, 1011, 1100, 1101, 1110, 1111, 10000 Write a non-member method binaryNumberSequence(int n) that produces the sequence of the first N integers. The method receives as parameter a number n, and returns a Queue<String> with n strings representing the first n integers converted to binary. The elements in the queue come in the increasing sequence order of the number. For example, a call to binaryNumberSequence(5) returns Q = {1, 10, 11, 100, 101}. You MUST create and store the binary number using division, mods, and a queue. LINKEDSTACKED IMPLEMENTATION public class LinkedStack<E> implements Stack<E> { @SuppressWarnings("hiding") private class Node<E> { private E element; private Node<E> next; public Node(E elm, Node<E> next) { this.element = elm; this.next = next; } public Node(E elm) { this(elm, null); } public Node() { this(null, null); } public E getElement() { return element; } public void setElement(E element) { this.element = element; } public Node<E> getNext() {
  • 2. return next; } public void setNext(Node<E> next) { this.next = next; } public void clear() { this.element = null; this.next = null; } } //End of Node Class private Node<E> header; private int currentSize; public LinkedStack() { this.header = new Node<>(); this.currentSize = 0; } @Override public void push(E newEntry) { if(newEntry == null) throw new IllegalArgumentException("Parameter cannot be null"); Node<E> newNode = new Node<>(newEntry, header.getNext()); header.setNext(newNode); currentSize++; } @Override public E pop() { if(isEmpty()) throw new EmptyStackException(); E elm = header.getNext().getElement(); Node<E> rmNode = header.getNext(); header.setNext(rmNode.getNext()); rmNode.clear(); rmNode = null; currentSize--; return elm; } @Override public E top() { if(isEmpty()) throw new EmptyStackException(); return header.getNext().getElement(); }
  • 3. @Override public boolean isEmpty() { return size() == 0; } @Override public int size() { return currentSize; } @Override public void clear() { while(!isEmpty()) pop(); } } BROWSER CLASS @Test public void test1() { String[] input = {"Google", "Facebook", "Instagram", "<", ">"}; String[] expected = {"Google", "Facebook", "Instagram", "Facebook", "Instagram"}; assertArrayEquals(expected, p.browserHistory(input)); } @Test public void test2() { String[] input = {"Google", "Facebook", "Instagram", "<", "<", ">", "Wikipedia", "Reddit", "<", "<", ">"}; String[] expected = {"Google", "Facebook", "Instagram", "Facebook", "Google", "Facebook", "Wikipedia", "Reddit", "Wikipedia", "Facebook", "Wikipedia"}; assertArrayEquals(expected, p.browserHistory(input)); } @Test public void test3() { String[] input = {"Google", "Facebook", "<", "<"}; String[] expected = {"Google", "Facebook", "Google"}; assertArrayEquals(expected, p.browserHistory(input)); } package lab5.problems; import java.util.ArrayList; import java.util.List;
  • 4. import lab5.util.dataStructures.LinkedStack; import lab5.util.interfaces.Stack; public class BrowserHistoryProblem { /** * TODO EXERCISE 1: * * In your Internet browser (e.g. Google Chrome), you can use the "back" and "forward" arrows * to navigate through your browsing history. * * Implement a non-member method called browserHistory(String[] clicks) that takes * a list of strings called clicks containing a mix of pages visited and back/forward arrow clicks, * and returns a list of the pages visited in order. * * It may be helpful to open a new Google Chrome tab and experiment with using the backward and forward buttons. *
  • 5. * Example: * Assume clicks = {"Google", "Facebook", "Instagram", "<", ">"}, * then a call to browserHistory(clicks) returns {"Google", "Facebook", "Instagram", "Facebook", "Instagram"} * because the user went backward to Facebook, then forward to Instagram. * * Here are some additional edge cases to consider: * * 1) The user may hit the back or forward buttons multiple times in a row. * 2) If the user tries to click the "back" or "forward" arrow even though * there is nowhere to go / it is greyed out, keep them on the same page without reloading the page. * 3) The user might refresh the page / visit the same page multiple times in a row. * Count these as a single visit. * 4) The user might visit the same page multiple times, but not necessarily in a row. Consider these distinct. *
  • 6. * Hint: Store the result and its values using an ArrayList<String> (import from java.util) as you * make your solution and return them as an array of strings using result.toArray(new String[result.size()]) * * WARNING: You MUST use a stack, implementations that use indices (or pointers) will receive ZERO credit. * * @param clicks - Array of strings denoting the web pages and clicks user made in their browser * @return The Array of strings with clicks made with the forward and back buttons replaced with * the corresponding page */ public String[] browserHistory(String[] clicks) { /*TODO ADD YOUR CODE HERE*/ return new String[0]; // Dummy Return } }