Sfoglia il codice sorgente

cars to pointer in prioq

Gildas Chabot 7 anni fa
parent
commit
8c8392adef
2 ha cambiato i file con 5 aggiunte e 5 eliminazioni
  1. 2 2
      main.go
  2. 3 3
      prioq.go

+ 2 - 2
main.go

@@ -26,8 +26,8 @@ type Ride struct {
26
 }
26
 }
27
 
27
 
28
 type Scheduler interface {
28
 type Scheduler interface {
29
-	Add(Car)
30
-	Pop() Car
29
+	Add(*Car)
30
+	Pop() *Car
31
 }
31
 }
32
 
32
 
33
 type Car struct {
33
 type Car struct {

+ 3 - 3
prioq.go

@@ -3,10 +3,10 @@ package main
3
 // Invariant: both children are bigger
3
 // Invariant: both children are bigger
4
 
4
 
5
 type prioq struct {
5
 type prioq struct {
6
-	bintree []Car
6
+	bintree []*Car
7
 }
7
 }
8
 
8
 
9
-func (pq *prioq) Add(car Car) {
9
+func (pq *prioq) Add(car *Car) {
10
 	pq.bintree = append(pq.bintree, car)
10
 	pq.bintree = append(pq.bintree, car)
11
 
11
 
12
 	// Rebalance tree to respect invariant
12
 	// Rebalance tree to respect invariant
@@ -19,7 +19,7 @@ func (pq *prioq) Add(car Car) {
19
 	}
19
 	}
20
 }
20
 }
21
 
21
 
22
-func (pq *prioq) pop() Car {
22
+func (pq *prioq) pop() *Car {
23
 	if len(pq.bintree) == 0 {
23
 	if len(pq.bintree) == 0 {
24
 		panic("Trying to remove from empty queue")
24
 		panic("Trying to remove from empty queue")
25
 	}
25
 	}