EBK DATA STRUCTURES AND ALGORITHMS IN C
4th Edition
ISBN: 9781285415017
Author: DROZDEK
Publisher: YUZU
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 4, Problem 4PA
Program Plan Intro
Implementation of the addingLargeNumbers()
Program Plan:
- In “addingLargeNumbers()” function
- It reads digits of first number from user one by one and pushes it into stack “Numm1_stack”.
- It reads digits of second number from user one by one and pushes it into stack “Numm2_stack”.
- Initialize “carryy” as “0”.
- Till “Numm1_stack” or “Numm2_stack” becomes empty,
- Add stack tops of both stacks with “carryy” and pop it from stacks.
- Push last digit of result into stack “Resultt_stack” and store carry in “carryy”.
- If “Numm1_stack” is not empty, till it becomes empty,
- Add stack top of stack “Numm1_stack” with “carryy” and pop it from stack.
- Push last digit of result into stack “Resultt_stack” ans store carry in “carryy”.
- If “Numm2_stack” is not empty, till it becomes empty,
- Add stack top of stack “Numm2_stack” with “carryy” and pop it from stack.
- Push last digit of result into stack “Resultt_stack” ans store carry in “carryy”.
- If “carryy” is not “0” push it into “Resultt_stack”.
- Till “Resultt_stack” becomes empty,
- Print stack top and pop it from stack.
- In “main()” function
- Call function “addingLargeNumbers()”.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Implement this algorithm:
Implement a function cross_out_multiples that takes as arguments a list of boolean values (true/false) called is_prime and a number n. The function
sets the boolean values at all multiples of n (2*n, 3*n, 4*n ...) that are in the list to false.
Implement a function sieve(n) which gives back a list of all primes below n.
Write a Java program that uses ArrayList and Iterator. It should input from user the names and ages of your few friends in a loop and add into ArrayList. Finally, it should use an Iterator to display the data in a proper format.
( Sample run of the program:-)
List of my Friends
Enter name and age [friend# 0]
Khalid Al-shamri
22.5
Do you want to add another friend (y/n)? y
Enter name and age [friend# 1]
Rahsed Al-anazi
21.1
Do you want to add another friend (y/n)? y
Enter name and age [friend# 2]
Salem Al-mutairi
23.7
Do you want to add another friend (y/n)? n
Here is the data you entered:
0. Khalid Al-shamri, 22.5
1. Rahsed Al-anazi, 21.1
2. Salem Al-mutairi, 23.7
Implement a recursive function void deleteMax() on the IntList class (provided). The function will delete from the IntList the IntNode containing the largest value. If there are multiple nodes containing this largest value, only delete the 1st one.
Be careful not to cause any memory leaks or dangling pointers.
You may NOT use any kind of loop (must use recursion).
You may NOT use global or static variables.
You may NOT use any standard library functions.
Ex:
list: 5->7->1->16->4->16->3
list.deleteMax();
list: 5->7->1->4->16->3
IntList.h
#ifndef __INTLIST_H__#define __INTLIST_H__
#include <ostream>
using namespace std;
struct IntNode {int value;IntNode *next;IntNode(int value) : value(value), next(nullptr) {}};
class IntList {
private:IntNode *head;
public:
/* Initializes an empty list.*/IntList() : head(nullptr) {}
/* Inserts a data value to the front of the list.*/void push_front(int val) {if (!head) {head = new IntNode(val);} else {IntNode…
Chapter 4 Solutions
EBK DATA STRUCTURES AND ALGORITHMS IN C
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
- Write a recursive function that finds the minimum value in an ArrayList. Your function signature should be public static int findMinimum(ArrayList<Integer>) One way to think of finding a minimum recursively is to think “the minimum number is either the last element in the ArrayList, or the minimum value in the rest of the ArrayList”. For example, if you have the ArrayList [1, 3, 2, 567, 23, 45, 9], the minimum value in this ArrayList is either 9 or the minimum value in [1, 3, 2, 567, 23, 45] Hint:The trick is to remove the last element each time to make the ArrayList a little shorter. import java.util.*; public class RecursiveMin{public static void main(String[] args){Scanner input = new Scanner(System.in);ArrayList<Integer> numbers = new ArrayList<Integer>();while (true){System.out.println("Please enter numbers. Enter -1 to quit: ");int number = input.nextInt();if (number == -1){break;}else {numbers.add(number);}} int minimum =…arrow_forwardWrite a recursive function that finds the minimum value in an ArrayList. Your function signature should be public static int findMinimum(ArrayList<Integer>) One way to think of finding a minimum recursively is to think “the minimum number is either the last element in the ArrayList, or the minimum value in the rest of the ArrayList”. For example, if you have the ArrayList [1, 3, 2, 567, 23, 45, 9], the minimum value in this ArrayList is either 9 or the minimum value in [1, 3, 2, 567, 23, 45] ================================================ import java.util.*; public class RecursiveMin{public static void main(String[] args){Scanner input = new Scanner(System.in);ArrayList<Integer> numbers = new ArrayList<Integer>();while (true){System.out.println("Please enter numbers. Enter -1 to quit: ");int number = input.nextInt();if (number == -1){break;}else {numbers.add(number);}} int minimum = findMinimum(numbers);System.out.println("Minimum: " + minimum);}public static int…arrow_forwardLet A={1,2,3...,10}. How many subsets B of A where B = │4│and the smallest element in B is 4? Write a computer program in java or develop an algorithm that lists all subsets according to the part (a). (Please display the all subsets).arrow_forward
- Solution in Java Create a function that takes an array of integers, sums the even and odd numbers separately, then returns the difference between the sum of the even and odd numbers. Examples warOfNumbers ([2, 8, 7, 5]) → 2 warOfNumbers ([12, 90, 75]) 27arrow_forwardWrite a program that obtains the executiontime of external sorts for integers of size 6,000,000, 12,000,000, 18,000,000,24,000,000, 30,000,000, and 36,000,000. Your program should print a tablelike this:arrow_forwardIn C++, write a program that outputs the nodes of a graph in a breadth first traversal. Data File: Please use this data file. Text to copy: 100 1 3 -9991 4 -9992 5 -9993 2 -9994 -9995 7 8 -9996 4 7 -9997 -9998 -9999 7 8 -999 Diagram: Also, please take a look at the attached figure on and calculate the weights for the following edges: 0 -> 1 -> 4 0 -> 3 -> 2 -> 5 -> 7 0 -> 3 -> 2 -> 5 -> 8 6 -> 4 6 -> 7 9 -> 7 9 -> 8 To calculates these weights, please assume the following data: 0 -> 1 = 1 0 -> 3 = 2 1 -> 4 = 3 3 -> 2 = 4 2 -> 5 = 5 5 -> 7 = 6 5 -> 8 = 7 6 -> 4 = 8 6 -> 7 = 9 9 -> 7 = 10 9 -> 8 = 11arrow_forward
- In C++, write a program that outputs the nodes of a graph in a breadth first traversal. Data File: Please use this data file. Text to copy: 100 1 3 -9991 4 -9992 5 -9993 2 -9994 -9995 7 8 -9996 4 7 -9997 -9998 -9999 7 8 -999 Diagram: Also, please take a look at figure 20-6 on page 1414 and calculate the weights for the following edges: 0 -> 1 -> 4 0 -> 3 -> 2 -> 5 -> 7 0 -> 3 -> 2 -> 5 -> 8 6 -> 4 6 -> 7 9 -> 7 9 -> 8 To calculates these weights, please assume the following data: 0 -> 1 = 1 0 -> 3 = 2 1 -> 4 = 3 3 -> 2 = 4 2 -> 5 = 5 5 -> 7 = 6 5 -> 8 = 7 6 -> 4 = 8 6 -> 7 = 9 9 -> 7 = 10 9 -> 8 = 11arrow_forwardThe sieve of Eratosthenes is a way of computing all the prime numbers below a certain number. (A prime number is a number that is only divisible by itself and 1). This algorithm is explained excellently in this video (Links to an external site.), or you can read about this ancient algorithm on Wikipedia (Links to an external site.). Implement this algorithm: Implement a function cross_out_multiples that takes as arguments a list of boolean values (true/false) called is_prime and a number n. The function sets the boolean values at all multiples of n (2*n, 3*n, 4*n ...) that are in the list to false. Implement a function sieve(n) which gives back a list of all primes below n.arrow_forwardThe sieve of Eratosthenes is a way of computing all the prime numbers below a certain number. (A prime number is a number that is only divisible by itself and 1). This algorithm is explained excellently in this video (Links to an external site.), or you can read about this ancient algorithm on Wikipedia (Links to an external site.). Implement this algorithm: Implement a function cross_out_multiples that takes as arguments a list of boolean values (true/false) called is_prime and a number n. The function sets the boolean values at all multiples of n (2*n, 3*n, 4*n ...) that are in the list to false. Implement a function sieve(n) which gives back a list of all primes below n. Needs to written in Python with the use of funtions and input parcersarrow_forward
- Write a program that randomly fills in 0s and 1s into a 6 * 6 matrix, prints the matrix, and finds the first row and first column with the least 1s.arrow_forwardUse java Write a code to determine a geodetic number (gn) of given simple graph. Your input file(.txt) will have the following adjacency matrix: 4 0 1 1 1 1 0 1 0 1 1 0 0 1 0 0 0 So, the first line indicates total number of vertices of the given graph and following lines are the rows or adjacency matrix with at least one white space between the characters. Following is the graph for that matrix. For the sake of simplicity; for any graph with n vertices, you may assume that graph vertices are from 0 to n-1 or 1 to n. This would help you to create two-dimensional array for adjacency matrix.arrow_forwardThe sieve of Eratosthenes is a way of computing all the prime numbers below a certain number. (A prime number is a number that is only divisible by itself and 1). Implement this algorithm: Implement a function cross_out_multiples that takes as arguments a list of boolean values (true/false) called is_prime and a number n. The function sets the boolean values at all multiples of n (2*n, 3*n, 4*n ...) that are in the list to false. Implement a function sieve(n) which gives back a list of all primes below n. Put your code in sieve.py This program is tested via unit tests.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