我试图根据给定的C bubblesort代码在ARM汇编程序中编写一个简单的bubblesort:
bubbleSort (int A[], int n)
{
int temp;
int i;
do {
swapped = false;
n = n-1;
for (i=0; i < n; i++) {
if ( A[i] > A[i+1] ) {
temp = A[i];
A[i] = A[i+1];
我选择了c++和haskell的研究生研究用的记录数组索引的二进制搜索,,写,c++代码和工作,现在我为haskell工作。
import Data.List
data BookInfo = Book Int String [String]
deriving (Show)
-输入变量
entering :: Int String [String]-> Book
entering id name subject= Book id name subject
-制作一个元组数组的idex
index :: [Book]->[Int]
in
#我希望将列表和算法(bubblesort)传递到带有需求(temp或wind_speed)的排序方法中。
class Reading:
def __init__(self, _temperature, _windspeed):
self.temp = _temperature
self.windspeed = _windspeed
def bubblesort(num):
for i in range (len(num)-1, 0, -1):
for j in range (i):
我用二进制搜索编写了在元组索引列表中搜索的程序。
superBubble::(Ord t) =>[[t]]->[[t]]
superBubble a=map bubbleSort a
combining::[BookInfo]->[Int]
combining books= bubbleSort(map index books)
binsearch :: [Int] -> Int -> Int -> Int -> Int -- list, value, low, high, return int
binsearch xs value low h
我正在尝试打开csv文件并将值从字符串转换为整数,这样我就可以对列表进行排序。我收到的结果是:
"[[],'190','200','250','350','90']“。
这是我的原始代码。
import csv
def bubbleSort(scores):
for length in range(len(scores)-1,0,-1):
for i in range(length):
if scores[i]>scores[i+1]:
我正在尝试使用数组来实现bubblesort,但是很难做到。到目前为止,我的情况如下:
fun swap(A, i, v) =
let
val temp = sub(A, i);
in
update(A, i, sub(A, v));
update(A, v, temp)
end;
这需要持续的时间,所以到目前为止一切都很好。
例外空;
fun bubbleSort(nil, i) = raise Empty
(* if has one element, already sorted)
| bubble
所以我的BubbleSort没有按正确的顺序打印数组的元素。在本例中,它打印出:4513。
我认为我写的程序是正确的,但我完全不知道该怎么做,所有的建议都很感谢,谢谢!
public class BubbleSort {
public void Print(){
}
public static void main(String[] args) {
// TODO Auto-generated method stub
int[] BubbleSort = {1, 5, 4, 3};
int l
到目前为止,我的代码是:
class Program
{
static void Main(string[] args)
{
Random r = new Random();
int n = r.Next(1, 10000);
int[] FortyKSet;
FortyKSet = new int[400];
for (int ndex = 0; ndex < FortyKSet.Length; ndex++)
{
FortyKSet[nde
对于我的任务,我需要生成一个随机数组,并按照从最小到最大的顺序排序,使用气泡排序以及搜索数组中的某些数字。我已经完成了大部分的任务,但我意识到,大约在数组的一半,我的气泡排序已经停止工作,因为在数字下降的秩序。所以前几个数可以是44,50,50,56,65,然后大约10到11个数字通过20个数字数组开始随机。这是我第一次使用泡泡排序,所以这可能是我不认识的一个小错误。
搜索函数也没有显示,因为在到达程序中的那个点之前,顺序显示错误,而且该函数也工作得很好。
int const MAX = 20;
int bubbleSort(int arr[], int length, int arrSele
我在python中有3种不同的冒泡排序方法,代码- 链接
我正在使用测试他们的性能。
从产出中:
Time taken[bubbleSort]: list size 1000 --> 0.0876331 seconds
Time taken[bubbleSort1]: list size 1000 --> 0.0575149 seconds
Time taken[bubbleSort2]: list size 1000 --> 0.000144 seconds
Time taken[bubbleSort]: list size 3000 --> 0.8421631
我是C#的新手,一直在玩它。我在C#中实现了一个气泡排序,因为它是一种编译语言,所以它比JavaScript更快,但是我的速度要慢得多。
我正在整理10万个数字。
在C#中,我的速度大约是:1分30秒
C#代码:
using System.Diagnostics;
public class Program {
public static void Main(string[] args) {
List<int> randoms = generateRandoms(0, 1000000, 100000);
Console.WriteLine
我正在尝试对bubbleSort算法进行基准测试。我曾经用time.time()来计时我的函数,并且希望用JavaScript来尝试同样的事情:
var time;
function bubbleSort(array) {
/*Function Time Starts Here*/
var start = Date.now();
for (var i = 0; i < array.length; i++) {
for (var j = 0; j < array.length; j++) {
if (array[j
我一直收到这个错误,我不知道它是什么意思。我已经采取措施在我的代码中去掉一个元组。程序应该读取一个包含一系列数字的文档,然后使用冒泡排序函数对这些数字进行排序,然后将旧列表和新的排序列表打印到新文件中。我的任务是创建一个新文件,并将给定文件中的原始数组和使用冒泡排序函数排序的排序数组打印为逗号分隔文件中的两行。 # reading in the document into the program
file = open("rand_numb.csv", "r")
# creating a new file that will have the output p
因此,我给自己一个任务,让一个伪码BubbleSort算法(按顺序)函数使用在一个更大的程序中,我对伪码非常陌生,所以我很想得到它的支持。我有Python代码:# Python: BubbleSort
def bubblesort(myList):
for i in range(0, len(myList) - 1):
for j in range(0, len(myList) - 1 - i):
if myList[j] < myList[j+1]:
myList[j], myList[j+1] = myL
我正在为一个课程编写一个程序,基本上它的思想是在排序之前跟踪一个数组中的元素,并在对大约9999个数字执行sorting.It工作后找到它的索引,但是当我输入一个大的输入作为18383833 (在第一个输入上)时,mac终端给我这个错误:分割错误: 11
下面是我的代码:
#include <stdio.h>
#include<stdlib.h>
void swap(int *xp, int *yp)
{
int temp = *xp;
*xp = *yp;
*yp = temp;
}
// A function to implement b
bubblesort2 :: (Ord a, Show a) => [a] -> [a]
bubblesort2 [] = []
bubblesort2 [x] = [x]
bubblesort2 (x:y:rest) =
bubblesort2 (init bubbled) ++ [last bubbled]
where
(first,second) = if x > y then (y,x) else (x,y)
bubbled = first : bubblesort2(second:rest)
我正在尝试理解下面的has
bubblesort2 :: (Ord a, Show a) => [a] -> [a]
bubblesort2 [] = []
bubblesort2 [x] = [x]
bubblesort2 (x:y:rest) =
bubblesort2 (init bubbled) ++ [last bubbled]
where
(first,second) = if x > y then (y,x) else (x,y)
bubbled = first : bubblesort2(second:rest)
我在试着理解上面的hask
我已经创建了一个新的冒泡排序项目,我想知道它需要多少时间。因此,我添加了一个返回nanotime的getTime()方法。我还创建了一个包含9个静态值的数组。当我运行我的代码时,我得到了不同的运行时间(例如:通常是3849 ns,但有时是6432或4277 ns)。这怎么可能呢?
我的代码如下:
long time2;
public void sort(int[] dizi){
long time = System.nanoTime();
for (int i = dizi.length-1; i >0; i--) {
for (int j = 0; j
我要去接ClassCastException。我一直在跟踪这个答案,但没有得到正确的答案。
BubbleSort.java
import java.util.ArrayList;
import java.util.List;
public class BubbleSort<T extends Number> {
public List<T> list;
@SuppressWarnings("serial")
public BubbleSort() {
list = new ArrayList<T>
我编写了一个小型Java程序,实现了int数组的冒泡排序技术。它适用于1000个单元的数组,但当我将其增加到10000时,它就会与java.lang.StackOverflowError崩溃。
以下是代码:
import java.util.*;
import java.lang.*;
class BubbleSort
{
public static void main (String [] argv)
{
int Array [] = new int [10000];
for (int a = 0; a < 10001; a++)
{
Arra
我正在尝试从文件中对列表进行排序,但是我得到了这个错误:
Traceback (most recent call last):
File "/Users/MacbookPro/Documents/Faculta/alg sortare pyth/bubble.py", line 13, in <module>
f = file.open('lista.txt', 'r')
AttributeError: type object 'file' has no attribute 'open'
这