March 2019
Intermediate to advanced
336 pages
9h 9m
English
The main method creates two orders, and the priority of the orders is set to 2 and 1. In the following code, the queue will first process the order with the higher number on the priority value:
// main methodfunc main() { var queue Queue queue = make(Queue,0) var order1 *Order = &Order{} var priority1 int = 2 var quantity1 int = 20 var product1 string = "Computer" var customerName1 string = "Greg White" order1.New(priority1,quantity1,product1, customerName1) var order2 *Order = &Order{} var priority2 int = 1 var quantity2 int = 10 var product2 string = "Monitor" var customerName2 string = "John Smith" order2.New(priority2,quantity2,product2, customerName2) queue.Add(order1) queue.Add(order2)var i intfor i=0; i< len(queue); ...Read now
Unlock full access