小编Abd*_*rbi的帖子

MIPS 中的冒泡排序算法

我正在尝试在汇编中编写一个程序,使用冒泡排序算法对数组进行排序,但我遇到的问题是:

在 中line 22,当第一次迭代执行时没有任何错误,程序array[i+1]完美地加载到注册器中$a1,并且如果交换条件有效,则程序交换没有任何问题。然而,在第二次迭代中,程序总是加载0$a1元素的实际值中!我尝试调试它,但什么都不清楚,我不知道这是什么原因。

1.  # Procedure:    bubbleSort
2.  # Objective:    sort an array of integer elements in nondecreasing order
3.  # Input:        an address of an array of integers
4.  # Output:       an array sorted in nondecreasing order
5. 
6.  bubbleSort:
7. 
8.  move    $t0, $a0     # move address of the array into $t0
9.  li      $s0, 1      # boolean swap = false.  0 --> false, 1 --> true …
Run Code Online (Sandbox Code Playgroud)

arrays assembly loops mips

2
推荐指数
1
解决办法
5万
查看次数

在 Django 中过滤单个对象的反向关系

假设我有以下两个模型:

class Person(models.Model):
    """
    A person model with the name of the person.
    """
    name = models.CharField()


class Vehicle(models.Model):
    """
    A vehicle model with the owner of the vehicle, and the type of the vehicle.
    A vehicle type could be a car, a truck or a bike.
    """
    owner = Models.ForeignKey(Person, related_name='vehicles')
    type = models.CharField()
Run Code Online (Sandbox Code Playgroud)

使用这两个模型,Django 将自动创建一个向后关系,其中一个人的所有车辆都可以通过以下查询访问:

    person = Person.objects.get(pk=1)
    person.vehicles.all()
Run Code Online (Sandbox Code Playgroud)

这将返回与该人相关的所有车辆,到目前为止一切顺利。

现在假设我想通过过滤车辆来获取 person 对象,假设我只需要自行车类型的车辆。我怎么能那样做?

为了将问题放在上下文中,我正在尝试构建以下网址:

    api.example.com/v1/person/1/vehicles/ [returns all vehicles]
    api.example.com/v1/person/1/vehicles/?type=bike [returns only vehicles of type bike]
Run Code Online (Sandbox Code Playgroud)

谢谢你。

python api django rest django-rest-framework

2
推荐指数
1
解决办法
2429
查看次数

标签 统计

api ×1

arrays ×1

assembly ×1

django ×1

django-rest-framework ×1

loops ×1

mips ×1

python ×1

rest ×1