Write the function called arrange that takes a list of integers (positive and negative) as an input parameter. The arrange function must use a deque data structure to arrange the integers so the negative numbers occur before the positive numbers (note that the function doesn't sort the values).  The function returns a new list containing the rearranged elements. For instance, for the input list [-3, 12, 6, -7, -1, 8], the function would return [-1, -7, -3, 12, 6, 8].   Write the main function to test the arrange function using various inputs.

Question

Write the function called arrange that takes a list of integers (positive and negative) as an input parameter. The arrange function must use a deque data structure to arrange the integers so the negative numbers occur before the positive numbers (note that the function doesn't sort the values).  The function returns a new list containing the rearranged elements. For instance, for the input list [-3, 12, 6, -7, -1, 8], the function would return [-1, -7, -3, 12, 6, 8].  

Write the main function to test the arrange function using various inputs.

 

dequeue.py file

class Deque:

  def __init__(self):

    self.items = []

  def is_empty(self):

    return self.items == []

  def add_front(self, item):

    self.items.append(item)

  def add_rear(self, item):

    self.items.insert(0,item)

  def remove_front(self):

    return self.items.pop()

  def remove_rear(self):

    return self.items.pop(0)

  def size(self):

    return len(self.items)     

Expert Answer

Want to see the step-by-step answer?

Check out a sample Q&A here.

Want to see this answer and more?

Experts are waiting 24/7 to provide step-by-step solutions in as fast as 30 minutes!*

*Response times may vary by subject and question complexity. Median response time is 34 minutes for paid subscribers and may be longer for promotional offers.
Tagged in
Engineering
Computer Engineering

Programing

Related Computer Engineering Q&A

Find answers to questions asked by students like you.

Q: The range of a set of values is the difference between the highest value and the lowest value in the...

A: Introduction of Program This C++ program takes the size of the array from the user then the user ent...

Q: Accept a paragraph of text consisting of sentencesthat are terminated by either ‘.’ (full stop), ‘!’...

A: The Java program is used to accept a paragraph of text which can have special symbols. And also it s...

Q: Scenario: The Ministry of Health is planning to build a mobile application software to screenpasseng...

A: a)  Agile software model is suitable for developing software in short time with accuracy. Sprints ar...

Q: im doing this practice assignment and it wants me to: Create a switch/case statement that tests v...

A: Points needed to be modified in the given code : Format of defining better image tag in Switch case ...

Q: Which input device exists on MC8088/EV Microcomputer Trainer and will be used when it is needed to p...

A: 8088 is common microprocessor which helped to know the structure and function of personal computers ...

Q: If there is forwarding, for the first five cycles during the execution of this code, specify which s...

A: Signals that are asserted during each cycle by hazard detection: From the figure, the outputs that ...

Q: Name two driving factors in the development of computers.

A: The primary need for computers was; problem-solving and automation or triggering of a series of even...

Q: Which of the following descriptions best describes  leaders?

A: A good leader will able to coordinate and integrate all the people towards to common goal which will...

Q: How is a logical database schema different from a physical database schema?

A: Difference between physical database schema and logical database schema: Some of the difference betw...

Q: Define recorder buffer.

A: The Recorder object proposes a mechanism for collecting and buffering any data (positions, speeds, e...

Q: using chapters 1 to 7 from the book c how to program 8 edition

A: A required program is as follows, #include<stdio.h> #define r 3 #define c 4 /*Define a functio...

Q: Using the Python interactive shell, instantiate a list that holds three-letter abbreviations for the...

A: >>> #Instantiate a list >>> six_months=["JAN","FEB","MAR","APR","MAY","JUN"] >&...

Q: Write the converse and inverse of the following statement.   If n is divisible by 6, then n is divis...

A: For the normal statement   if p then q The converse statement is if q then p The inverse statement i...

Q: Design a logic circuit to implement the operation specified in the truth table given below. Truth ta...

A: Click to see the answer

Q: Define a new class named UnweightedGraphFindCycle thatextends UnweightedGraph with a new method for ...

A: Program: Exercise.java: //import the required packages import java.util.List; import java.util.Array...

Q: 2. Design the distributed algorithm for the following problem with Condition 1 using Round Model, wh...

A: The system is distributed with n kids playing in a ground. When the teacher asks them to form a circ...

Q: Help please m

A: BCD-Binary Coded Decimal which will have 4 bits. So split the given BCD into each four bits and get ...

Q: To move data from one part of the document to another, the following is used: O Cut and delete Cut a...

A: Moving data from one part of document to another Copy is used for making duplicates that leaves the...

Q: Problem 1: Highlight the data path that is active during the execution of the following MIPS instruc...

A: Actually, the answer has given below:

Q: Which protocol can provide VoIP services over a Metro Ethernet connection?

A: Voice communication over internet is called as VoIP (Voice over Internet Protocol) or internet telep...

Q: Explain the behavior of the following shell script: $ cat quote_demo twoliner="This is line 1. This...

A: In below statement 'echo receives 2 arguments. $  echo "$twoliner"  To understand how the variable i...

Q: What would you say to a vendor who tells you that his system runs 50% of the SPEC benchmark kernel p...

A: Performance of the system: System performance is considered as one of main factor of a processor. I...

Q: I want detailed information and a guide for using Microsoft network monitor 3.1.؟

A: Microsoft Network Monitor 3.1: Wireless (802.11) capturing and monitor mode on Vista – With support...

Q: For each of the following collection of entities, give the assumptions concerning the relationship b...

A: EMPLOYEE(EMP_NUM, EMP_LNAME, EMP_INITIAL, EMP-DOB) Here, primary key = EMP_NUM DEPENDENT(EMP_NUM, DE...

Q: Write a program which consists of a user defined function: compute (), it should take one integer ar...

A: Here the program is used is C++. It will return the count of odd Fibonacci terms from starting to th...

Q: what is cloud backup solutions? are there any websites which offer large storage for free

A: Cloud Backup: Cloud Backup is a service that backups and stores the data and applications on a remot...

Q: Answer the following questions regarding your system by using the commands listed inthis chapter. Fo...

A: a. Total number of inodes in the root filesystem: The command for getting the inodes details like th...

Q: Draw the timing diagram for MARIE’s Load instruction using the format of Figure 4.16.

A: Click to see the answer

Q: The command chmod 317 file1 would produce which of the following lines in thels command?a. --w-r--rw...

A: Answer is given below,

Q: Write a Program to define a Student class, with member variables String name; intcms String DegreeP...

A: public class Student{   //creating specified data members private String name; private String Degree...

Q: Using the CRC polynomial 1101, compute the CRC code word for the information word 01011101. Check th...

A: Introduction of  CRC: A cyclic redundancy check is a method to detect an error in the communication ...

Q: Linux is a__________ and__________ operating system.a. production, stableb. multiuser, multitaskingc...

A: Linux: Linux is a multi-user and multi-tasking operating system. Linux is a multiuser operating sys...

Q: An object is in location (1,3), (1,6), (3,3) and (3,6). Do two repeated translation operations on th...

A: Given Translation vector V(h,k) =(2,1) The new coordinates of a point A(x,y) over a translation of V...

Q: explain when you would prefer time-sharing processing instead of batch processing.

A: Time sharing processing  Time sharing processing is used when the tasks are given specific time and...

Q: 1. Write an algorithm to determine whether a given element x belongs to a set S := {s1, . . . , sn}.

A: Given information: An algorithm to determine whether a given element belongs to a given set that is...

Q: create a mind-map of a SWOT analysis, focusing on a project for improving teaching and learning serv...

A: Make changes to SWOT analysis techniques-Mind Map Full FORM OF SWOT - Strengths, Weaknesses, Opport...

Q: Explain briefly in your own words the main disruptive technologies for 6G that you consider to drast...

A: The sixth generation wireless networking system is the successor of 5 G cellular technology. It is e...

Q: Consider Figure 3.58 . Assuming TCP Reno is the protocol experiencing the behavior shown above, answ...

A: Suppose TCP Tahoe is used  and assuming  that triple duplicate acknowledgement  is been received at ...

Q: What memory blocks will be in the cache after the last address has been accessed?

A: There are  4 memory blocks namely : Block 0 Block 1 Block 2 Block 3 Each block has the different t...

Q: Explain the relationship among disk platters, tracks, sectors, and clusters.

A: Introduction of Hard Disk: A hard disk is used to store data in a computer system. In a computer sys...