1. Homepage
  2. Programming
  3. 159201 Algorithms & Data Structures Assignment 3: Router Simulation

159201 Algorithms & Data Structures Assignment 3: Router Simulation

Engage in a Conversation
Massey159201Algorithms & Data StructuresRouter SimulationC++

159.201 Algorithms & Data Structures Assignment 3 CourseNana.COM

A router reads packages from input ports and writes them to output ports based on their address. Input and output ports are numbered 0 . . . 255. During each cycle, an arbitrary number of packages arrives at the input queues. The router then tries to read one package from each input port queue, in order (starting with port 0), and if available writes it to the matching output port queue. For clarity, one cycle consists of (a) reading any number of packets into input queues, and (b) sending one packet per input queue to the specified output queue. CourseNana.COM

Processing proceeds cycle by cycle, until no more inputs arrive and all input queues are empty (so that all packets have been sent to output queues). CourseNana.COM

Write a C++ program that simulates such a router, reading from standard input and writing to standard output. The input consists of one line per input cycle, in the format CourseNana.COM

n port1 addr1 value1 ... portn addrn valuen CourseNana.COM

Here n denoted the number of packages arriving in this cycle, port describes the input port where the package arrives, addr is the output port the package is destined for, and value is the payload. Payloads are single word strings, all other inputs are integers. CourseNana.COM

Your program should print one line per output port that has packages sent to it. Each line should start with the port number, then list all payloads in the order they arrived in the output queue, separated by a single space character. For example: CourseNana.COM

Input Output 223easy21was 1thatwas 2 1 1 that 2 3 ... 3 easy ... CourseNana.COM

You can use CodeRunner to test your work, but must submit your assignment as usual. CourseNana.COM

CourseNana.COM

Detailed example how the input above is processed:
Cycle 1 (load): load packets (2,3,easy) and (2,1,was) into the input queues: CourseNana.COM

Input Queues
2: (3,easy) (1,was)
CourseNana.COM

Output Queues CourseNana.COM

  • Cycle 1 (process): transfer the first packet from each input queue: Input Queues Output Queues
    2: (1,was) 3: easy
    CourseNana.COM

  • Cycle 2 (load): load packets (1,1,that) and (2,3,...) into the input queues: Input Queues Output Queues
    1: (1,that) 3: easy
    2: (1,was) (3,...)
    CourseNana.COM

  • Cycle 2 (process): transfer the first packet from each input queue: Input Queues Output Queues
    2: (3,...) 1: that was
    CourseNana.COM

    3: easy
    Note: queues are processed 0..255, so (1,that) is transfered before (1,was). CourseNana.COM

  • Cycle 3 (load): no input pending, but input queues are not empty yet CourseNana.COM

  • Cycle 3 (process): transfer the first packet from each input queue: Input Queues Output Queues CourseNana.COM

    1: that was 3: easy ... CourseNana.COM

  • Cycle 4 (load): no input pending, and input queues are empty  CourseNana.COM

Get in Touch with Our Experts

WeChat WeChat
Whatsapp WhatsApp
Massey代写,159201代写,Algorithms & Data Structures代写,Router Simulation代写,C++代写,Massey代编,159201代编,Algorithms & Data Structures代编,Router Simulation代编,C++代编,Massey代考,159201代考,Algorithms & Data Structures代考,Router Simulation代考,C++代考,Masseyhelp,159201help,Algorithms & Data Structureshelp,Router Simulationhelp,C++help,Massey作业代写,159201作业代写,Algorithms & Data Structures作业代写,Router Simulation作业代写,C++作业代写,Massey编程代写,159201编程代写,Algorithms & Data Structures编程代写,Router Simulation编程代写,C++编程代写,Masseyprogramming help,159201programming help,Algorithms & Data Structuresprogramming help,Router Simulationprogramming help,C++programming help,Masseyassignment help,159201assignment help,Algorithms & Data Structuresassignment help,Router Simulationassignment help,C++assignment help,Masseysolution,159201solution,Algorithms & Data Structuressolution,Router Simulationsolution,C++solution,