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 1PA
Program Plan Intro
Program Plan:
- In “main()” function
- Declare variables “stackk1” and “stackk2” for two stacks and “char_ele” for character of string.
- Initializing length of string “lengthh” and flag to check palindrome “flag_palleo” as “0”.
- Read each character of string from keyboard and push it into “stackk1” and increment “lengthh” by one.
- If length of string “lengthh” is even, pop half number of characters from “stackk1” and push it into “stackk2”.
- If “lengthh” is odd, pop half number of characters from “stackk1” and push it into “stackk2”.And pop middle character of string from “stackk1”.
- For half number of characters in string, compare tops of both stacks. If both are same then pop top of both stacks.
- If tops of two stacks are not same, set flag value as “1” and break from loop.
- Finally check the value of flag. If flag value is “1”, print the message that string is not palindrome.
- If flag value “0”, print the message that string is palindrome.
Expert Solution & Answer
Trending nowThis is a popular solution!
Students have asked these similar questions
Use stacks from the STL to implement a video game library functionality. In this implementation, consider a VideoGame class with title, release year, genre and publisher as variables. Provide setters and getters to these variables.
In main, create a stack of video games. Add 5 different game objects into the stack. Then in a loop, for each item that you retrieve from the stack display the game information as follows:
TITLEYEARGENREPUBLISHER
Write a java method to search for an element in an array using a linear search. Many list processing tasks, including searching, can be done recursively. The base case typically involves doing something with a limited number of elements in the list (say the first element), then the recursive step involves doing the task on the rest of the list. Think about how linear search can be viewed recursively; if you are looking for an item in a list starting at index i:o ¬If i exceeds the last index in the list, the item is not found (return -1).o ¬If the item is at list[i], return i.o ¬If the is not at list[i], do a linear search starting at index i+1
Python please...
Implement a function printIndex() that takes a list as a parameter, prompts the user to enter a whole number n, and prints the element in position Index[n]. If the list is empty ([]) or n is not a valid index into the list, the function will not print anything. Be careful to do the correct thing with negative indices. You should assume that the user will enter a whole number when prompted, and the function will crash if the user does not enter an integer. The function should not change the list passed as a parameter. Hint: Just because this involves a list does not mean that you need a loop to solve the problem. Think carefully about the right construct to use here. The following shows the function template, and several examples runs of the function (you must show all the examples with these values in your submission):
Template
def printIndex(lst):
replace with your docstring
newList = lst # ________________________
elementNum =…
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 java program using stacks: 1. For a given expression in the form of a string, find if there exist any redundant brackets or not. It is given that the expression contains only rounded brackets or parenthesis and the input expression will always be balanced. A pair of the brackets is said to be redundant when a sub-expression is surrounded by unnecessary or needless brackets. Sample Input 1: (a+b)+c Sample Output 1: false Explanation: Since there are no needless brackets, hence, the output must be 'false'. Sample Input 2: ((a+b)) Sample Output 2: true Explanation” The expression can be reduced to (a+b). Hence the expression has redundant brackets and the output will be 'true'.arrow_forwardIt's a very nice application of stacks. Consider that a freight train has n railroad cars. Each to be left at different station. They're numbered 1 through n & freight train visits these stations in order n through 1. Obviously, the railroad cars are labeled by their destination. To facilitate removal of the cars from the train, we must rearrange them in ascending order of their number (i.e. 1 through n). When cars are in this order, they can be detached at each station. We rearrange cars at a shunting yard that has input track, output track & k holding tracks between input & output tracks (i.e. holding track). The figure shows a shunting yard with three holding tracks H1, H2 & H3, also n = 9. The n cars of freight train begin in the input track & are to end up in the output track in order 1 through n from right to left. The cars initially are in the order 5,8,1,7,4,2,9,6,3 from back to front. Later cars are rearranged in desired order. To rearrange cars, we…arrow_forwardPlease answer it in Python Write a program that asks the user for strictly positive numbers and stores them in a list. The input stops as soon as the user enters "0" (zero). Then view the average of this list. Write a program that reverses the order of items in a list. For example [1, 3, 9, 6, 4] must become [4, 6, 9, 3, 1]. Note: There are several ways to solve this problem. You are free to keep a single list from start to finish, or create temporary lists, add, delete values, etc.arrow_forward
- Write a java code that sorts a list of n items by dividing it into three sublistsof about n/3 items, sorting each sublist recursively and merging the threesorted sublists. Analyze your algorithm, and give the results under ordernotation.arrow_forwardWrite a program to maintain a list of items as a circular queue, which is implemented using an array. Simulate insertions and deletions to the queue and display a graphical representation of the queue after every operation.arrow_forwardImplement a Python program that reads a list of integers from the user, removes any duplicate elements, and then prints the modified list. The program should maintain the original order of elements while removing duplicates.arrow_forward
- Please write the programs in python. Let there are N numbers in a list and that list is said to be a UB Jumper if the absolute values of the difference between the successive elements take on all the values 1 through N − 1. For example, 2 1 4 6 10 is a UB Jumper because the absolute differences between them are 1 3 2 4 which is all numbers from 1 to (5 - 1) or 4. Write a python program that takes a number sequence as input and prints whether it is a UB Jumper or Not UB Jumper. Input will stop after getting “STOP” as input. (Number order or absolute difference order doesn’t follow any sequence.) Sample Input 14232 1 4 6 10 1 4 2 -1 6 STOP Sample Output UB JumperUB Jumper Not UB Jumper You are given a string that contains alphanumeric characters only. Your task is to sort the string in the following manner: All sorted lowercase letters are ahead of uppercase letters. All sorted uppercase letters are ahead ofdigits. All sorted odd digits are ahead of sorted even digits.…arrow_forwardGiven a stack of positive integers, write a Java method called movePrimes that rearranges elements of the stack such that all prime numbers are below none primes regardless to the order of primes. Note: You are allowed to create only one other stack. You can not use other data structures such as array, arraylist, queue, ....etc. Consider the following example:arrow_forwardWrite a Java program to input a list of names (strings) from the user and store them in an ArrayList. The input can be terminated by entering the empty string or b yentering the string “quit”.arrow_forward
- Write a program SentenceReverser that reverses the words in a sentence by reading words into a Stack until you find a period. Your program should then pop off the words from the stack. Begin your reverse sentence with a capital letter and end it with a period. Your program should be able to handle multiple sentences. Use while (scan.hasNext()) to capture your input. Mary had a little lamb. His fleece was as white as snow. Becomes: Lamb little a had mary. Snow as white as was fleece his. Note: Your test input should include multiple sentences as shown above. There should NOT be a space before your periods.arrow_forwardWrite a program using the stack for parenthesis matching. Explain what modifications would be needed to make the parenthesis matching algorithm check expressions with different kinds of parentheses such as (), ] and (}'s. Please write simple C programs to answer the question. Examine your codes with some examples. You should upload your runnable codes + report (single pdf) that explains your codes and results as a single zip file.arrow_forwardComputer Science Given two polynomials in form of strings. How to use Java program that adding, subtracting, and multiplying two polynomials using singly linked lists. Using a singly linked list to represent a polynomial. Each term will be saved in a node in the list. The length of the list will be the number of terms in the given polynomial. Input: The input will be two polynomials in the following form of strings, for example: "(-4.5)X^1 + (-2.5)X^0 + 1X^3" "1X^2 + 1X^0" Output: Polynomial p: X^3 -4.5X -2.5 Polynomial q: X^2 + 1.0 p+q: X^3 + X^2 -4.5X -1.5 p-q: X^3 -X^2 -4.5X -3.5 p*q: X^5 -3.5X^3 -2.5X^2 -4.5X -2.5 import java.util.StringTokenizer; public class Term { private double coeff; private int pow; } import java.util.StringTokenizer; public class Polynomial { private SinglyLinkedList<Term> p; public Polynomial(String st) { } public Polynomial add(Polynomial q) { } public Polynomial subtract(Polynomial q) { } public Polynomial multiply(Polynomial q) { } public…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning