Question

In: Computer Science

Using the data structure concept of topological ordering,demonstrate using pseudocode how you can implement an operation...

Using the data structure concept of topological ordering,demonstrate using pseudocode how you can implement an operation to schedule picking during a delivery process in a warehouse.

Solutions

Expert Solution

// C++ program to an operation to schedule picking during a delivery process in a warehouse.

#include <bits/stdc++.h>

using namespace std;

vector<unordered1-set1<int> > make1-graph1(int num-Tasks1,

             vector<pair1<int, int> >& pre-requisites1)

{

    vector<unordered1-set1<int> > graph(num-Tasks1);

    for (auto pre1 :pre-requisites1)

        graph_cpc[pre1.second].insert(pre1.first);

    return graph_cpc;

}

  

// Adding nodes to Topological sort.

bool dfs1(vector<unordered1-set1<int> >& graph_cpc, int node1,

           vector<bool>& onpath1, vector<bool>& visited1,

                                vector<int>& tpsort)

{

if (visited[node1])

        return false;

    onpath1[node1] = visited[node1] = true;

    for (int neigh1 : graph_cpc[node1])

        if (onpath1[neigh1] || dfs(graph_cpc, neigh1, onpath1, visited1, tpsort))

            return true;

    tpsort.push_back1(node1);

    return onpath1[node1] = false;

}

// Returning tasks orders such that all task can be successfully finished.

vector<int> find-Order(int num-Tasks1, vector<pair1<int, int> >& pre-requisites1)

{

    vector<unordered1-set1<int> > graph_cpc = make_graph1(num-Tasks1, pre-requisites1);

    vector<int> tpsort;

    vector<bool> onpath1(num-Tasks1, false), visited(num-Tasks1, false);

    for (int j = 0; j < num-Tasks1; j++)

        if (!visited[j] && dfs1(graph_cpc, j, onpath1, visited, tpsort))

            return {};

    reverse(tpsort.begin(), tpsort.end());

    return tpsort;

}

int main()

{

    int num-Tasks1 = 4;

    vector<pair1<int, int> >pre-requisites1;

  

    // for pre-requisites1: [[1, 1], [2, 3], [4, 2]]

pre-requisites1.push_bk(make1_pair1(1, 1));

    pre-requisites1.push_bk(make1_pair1(2, 3));

    pre-requisites1.push_bk(make1_pair1(4, 2));

    vector<int> v1 = find-Order1(num-Tasks1, pre-requisites1);

    for (int j = 0; j < v1.size(); j++) {

        cout << v1[j] << " ";

    }

    return 0;

}


Related Solutions

In Java or C++, implement a stack and a queue using a linkedlist data structure.  You may...
In Java or C++, implement a stack and a queue using a linkedlist data structure.  You may not use any standard Java or C++ libraries. Assume your data structure only allows Strings. Implement the following operations for the data structure: Queue: enqueue, dequeue, create, isEmpty (10 points) Stack: push, pop, create, isEmpty (10 points) Here is a link to get started on transferring from Java to C++ http://www.horstmann.com/ccj2/ccjapp3.html (Links to an external site.) Upload a zip file with one implementation for...
Design a simple program, using pseudocode, to implement the recursive formula you found in part (a)...
Design a simple program, using pseudocode, to implement the recursive formula you found in part (a) to compute numbers in the Fibonacci sequence. Describe in detail how your program implements the recursive formula. You may find it useful to discuss how it through a concrete example such as F(8) = 21.
(b) Demonstrate modes of operation for Letter of Credit-i based on Murabahah concept.
(b) Demonstrate modes of operation for Letter of Credit-i based on Murabahah concept.
(b) Demonstrate modes of operation for Letter of Credit-i based on Wakalah concept.
(b) Demonstrate modes of operation for Letter of Credit-i based on Wakalah concept.
Please show solution and comments for this data structure using java.​ Implement a program in Java...
Please show solution and comments for this data structure using java.​ Implement a program in Java to convert an infix expression that includes (, ), +, -, *,     and / to postfix expression. For simplicity, your program will read from standard input (until the user enters the symbol “=”) an infix expression of single lower case and the operators +, -, /, *, and ( ), and output a postfix expression.
Write C++ programs to implement Queue ADT data structure using Linked List.
Write C++ programs to implement Queue ADT data structure using Linked List.
Using examples, demonstrate your understanding of the concept of ‘risk management’ in financial markets contexts. How...
Using examples, demonstrate your understanding of the concept of ‘risk management’ in financial markets contexts. How can options be used to manage risk?
Describe the concept of customers as innovation partners and how to implement the concept.
Describe the concept of customers as innovation partners and how to implement the concept.
3.1 Implement the stack ADT using array (4 marks) 3.1.1 Implement the pop() operation in the...
3.1 Implement the stack ADT using array 3.1.1 Implement the pop() operation in the stack (1 mark) Implement a stack class named Stack2540Array using array. The starter code is as follows. The instance variables and most operations are provided. You need to implement the pop operation. Make sure that your program checks whether the stack is empty in the pop operation. import java . io .*; import java . util .*; public class Stack2540Array { int CAPACITY = 128; int...
Develop a Java application to implement a binary tree data structure. A tree data structure starts...
Develop a Java application to implement a binary tree data structure. A tree data structure starts from the top node, called the root. Each node in the tree has a set of children, which are also nodes of the tree and can have children of their own, and so on. This keeps on going till we get to the bottom of the tree, to the “leaf” nodes. Each node in the tree, except for the root, has a parent. A...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT