¿Por que mi programa se cae al declarar un array grande en C?

estoy intentando conseguir datos para poder graficar la complejidad algorítmica de shell sort.
Lo que hace el programa es almacenar datos desde otro archivo (en esto no hay problema) pero al momento de crear el array con “x” cantidad de datos simplemente el programa se cae y no responde.
La verdad esto tiene un tope, aproximadamente para un array con 520.000 espacios el programa se cae, para inferiores ningún problema.

El programa es el siguiente y N es la cantidad de espacios que tiene el array que serán llenados con datos (solo números).

#include<stdio.h>
#include <time.h>
void llena_array(long int *array,int n);
void muestra_array(long int *array,int n);

int main(){
    int n;
    printf("Cuantos datos? ");
    scanf("%d",&n);
    long int a(n);
    
    llena_array(a,n);
    //muestra_array(a,n);

    int temp=0,i,j,gap;
    time_t t_1,t_2;
    
    t_1=time(NULL);
    //shell sort
    for(gap=n/2;gap>=1;gap/=2){
        for(j=gap;j<n;j++){
            for(i=j-gap;i>=0;i=i-gap){
                if(a(i+gap)>a(i)){
                    break;
                }
                else{
                    temp=a(i);
                    a(i)=a(i+gap);
                    a(i+gap)=temp;
                }
            }
        }
    }
    t_2=time(NULL);

    printf("nCantidad de datos = %d",n);
    printf("nTiempo Total = %lfn",difftime(t_2,t_1));  

    //printf("Luego de shell sort..n");
    //muestra_array(a,n);
}

void llena_array(long int *array,int n){
    FILE *entrada;
    int i;
    int dato;
    entrada = fopen("datos_ordenados.txt","r");
    for (i = 0; i < n; i++){
        fscanf(entrada, "%d", &dato);
        array(i) = dato;
    }
    fclose(entrada);
}
void muestra_array(long int *array, int n){
    int i;
    for (i=0;i<n;i++){
        printf("%dn",array(i));
    }
}

¿Que podría hacer para evitar/solucionar este problema?,quisiera poder obtener el tiempo de ejecución con 600.000 datos pero no he podido, y la verdad no conozco muy bien sobre el tema.

Invocando shell_sort desde cmd de windows 10
Imagen demostrativa

Google Sheet: Array formula – Web Applications Stack Exchange

I made this formula: ={filter(Sheet1!B1:AA22;Sheet1!B23:AA23=SAND);filter(Sheet1!B26:AA47;Sheet1!B48:AA48=SAND)}

(The “=sand” is just “=true” in my language)

But i keep getting “An Array Literal was missing values for one or more rows”

I have no idea what is wrong. Ive been trying stuff for over an hour, and each filter works as intended until i combine them in the {}.

Its in this sheet, in sheet2 cell C3: https://docs.google.com/spreadsheets/d/1z1Mbqcmnm8hu0ZN5HdSw_JI3bhby0lP7Z03NIg5vmKg/edit?usp=sharing

Anyone got an idea what is wrong? Thanks alot!

javascript – Sorting an array of positive integers including 0 much faster than Radix Sort

I was working on an Limit Order Book structure in JS and came up with this algorithm. I am pretty sure this must have already been implemented but couldn’t even find a clue over the web.

The thing is, it’s very fast especially when you have an array of many duplicate items. However the real beauty is, after inserting k new items into an array of already sorted n items the pseudo sort (explained below) takes only O(k) and sort takes only O(n+k). To achieve this i keep a pseudo sorted array of m items in a sparse array where m is the number of unique items.

Take for instance we need to sort (42,1,31,17,1453,5,17,0,5) where n is 9 and then we just use values as keys and construct a sparse array (Pseudo Sorted) like;

Value: 1 1 2  2  1  1    1
Index: 0 1 5 17 31 42 1453

Where Value keeps the repeat count. I think now you start to see where I am getting at. JS have a fantastic ability. In JS accessing the sparse array keys can be very fast by jumping over the non existent ones. To achieve this you either use a for in loop of Object.keys().

So you can keep your sparse (pseudo sorted) array to insert new items and they will always be kept in pseudo sorted state having all insertions and deletions done in O(1). Whenever you need a real sorted array just construct it in O(n). Now this is very important in a Limit Order Book implementation because say you have to respond to your clients with the top 100 bids and bottom 100 asks in every 500ms over a web socket connection, now you no longer need to sort the whole order book list again even if it gets updated with many new bids and asks continuously.

So here is sparseSort code which could possibly be trimmed up by employing for loops instead of .reduces etc. Still beats Radix and Array.prototype.sort().

function sparseSort(arr){
    var tmp = arr.reduce((t,r) => t(r) ? (t(r)++,t) : (t(r)=1,t),());
    return Object.keys(tmp)
                 .reduce((a,k) => {
                           for (var i = 0; i < tmp(k); i++) a.push(+k);
                           return a;
                         },());
}

Here you can see a bench against Array.prototype.sort() and radixSort. I just would like to know if this is reasonable and what might be the handicaps involved.

javascript – Agrupar valores repetidos en un array de objetos – React

Hola estoy intentando eliminar los valores repetidos en un array de objetos. Tengo el siguiente json:

(
  {
    id: 0,
    day: "Lunes",
    openingHours: "6:00 a.m",
    closingHours: "12:00 p.m"
  },
  {
    id: 1,
    day: "Martes",
    openingHours: "6:00 a.m",
    closingHours: "12:00 p.m"
  },
  {
    id: 2,
    day: "Miércoles",
    openingHours: "6:00 a.m",
    closingHours: "12:00 p.m"
  },
  {
    id: 3,
    day: "Jueves",
    openingHours: "6:00 a.m",
    closingHours: "12:00 p.m"
  },
  {
    id: 4,
    day: "Viernes",
    openingHours: "6:00 a.m",
    closingHours: "12:00 p.m"
  },
  {
    id: 5,
    day: "Sábado",
    openingHours: "6:00 a.m",
    closingHours: "12:00 p.m"
  },
  {
    id: 6,
    day: "Domingo",
    openingHours: "6:00 a.m",
    closingHours: "12:00 p.m"
  }
);

Como pueden ver, los valores de las propiedades openingHours y closingHours están repetidos. Agrego ese json a mi componente <App />, a continuación el componente:

import React, { useState } from 'react';
import './App.css';
import days from './days.json';

function App() {

  const (schedule, setSchedule) = useState(days),

  updateDays = () => {
    //update days
  };

  return (
    <div className="container">
      {
        schedule.map(x => (
          <>
          <div style={{marginBottom: 10, borderBottom: '.5px solid black', paddingBottom: 5}}>
          <b>{x.day}{x.firstDay}{x.firstDay ? ' - ' : null}{x.lastDay}: </b><span>{x.openingHours} - {x.closingHours}</span><br />
          </div>
          </>
        ))
      }
      <button id="button" onClick={updateDays} style={{marginTop: 20}}>Actualizar horario</button>
    </div>
  );
}

export default App;

Hago un mapeo al estado schedule y dependiendo de los elementos renderizo el dia del item, su fecha de apertura y de cierre (openingHours, closingHours). Ahora en el json no existe las propiedad firstDay y lastDay , debido a que estas se deben crear siempre y cuando, hayan días con la misma hora de entrada y de salida.

CASO 1: En el json actual, la salida debe ser: Lunes – Domingo: 6:00 a.m – 12:00 p.m, porque desde Lunes hasta el Domingo se repiten ambas horas.

CASO 2: Ahora si se modifican las fechas en el json, Ejm: si el día Lunes hasta el Miércoles tengan las mismas horas y estás no sean iguales a los demás días, la salida debe ser:

Lunes – Miécoles: 7:00 a.m – 11:00 p.m (estás fechas pueden ser cualquier otra)

Jueves – Domingo: 6:00 a.m – 12:00 p.m

CASO 3: Ahora si todas las fechas entre si son diferentes, debe mostrar todos los días con sus respectivas fechas, es decir, si en el json se modifican todas las fechas y no son equivalentes entre sí.

Siempre debe agrupar los días en los que siempre sean iguales tanto su openingHours como closingHours, un ejm más claro lo pueden ver como funcionan los horarios de las páginas de Facebook, te agrupa los días en los que sean iguales ambas horas.

Muchas gracias por su atención, ultimamente estuve trabajando con arrays y me está costando un poco.

algorithms – I have just created a program to create a heap out of the input array, but my output does not match, please point the error

#include
using namespace std;
int swap(int dumb ,int i, int temp)
{
int jigle=
(dumb+temp);
(dumb+temp)=(dumb+i);
*(dumb+i)=jigle;
return 0;
}
int main()
{
int a(6)={32,40,15,50,5,44};
int n=6;

int *dumb=new int(n);
for(int i=0;i<n;i++)
{
    *(dumb+i)=*(a+i);
    if(i>0)
    {
        int temp=(i-1)/2;
        while(*(dumb+i)>*(dumb+temp))
        {
            swap(dumb,i,temp);
            i=temp;
            temp=(i-1)/2;
         if(i==0)
            {
                break;
            }
        }
    }
}
for(int i=0;i<n;i++)
{
    cout<<*(dumb+i)<<"n";
}

}

OUTPUT:
50
50
15
50
5

bash – Issue with converting array or string to valid path

I’m trying to make a function that will make my life easier converting images to pdf. I’m using img2pdf which is a Python script. I want to be able to pass files and directory to my function (with wild mark for expansion like: directory/*).

I come to a point where I fix the issues with Windows path conversion, but then realize now the function doesn’t work if the path has spaces, or it comes to a point where Python will just error on pathing.

I tried writing the function, making a string that contains all the files:

imgtopdf(){
    list=""
    while (( "$1" != "" )) ; do
        list+=" '$(cygpath -w "$1")'" # Tried $(echo "$list" | xargs -0) echo but it removes back-slashes!
        shift
    done
    list="${list:1}"
    echo $list
    img2pdf -o img2pdf.pdf --pagesize A4 $list
}

Then tried using an array to hold all the files:

imgtopdf(){
    list=()
    while (( "$1" != "" )) ; do
        list+="$(cygpath -w "$1")"
        shift
    done
    echo ${list(@)}
    img2pdf -o img2pdf.pdf --pagesize A4 ${list(*)}
}

Note: cygpath -w is responsible for converting a /cygdrive/ path to Windows path, so that Python understands the pathing.

unity – Iterating through an array to check if all variables have a certain value

unity – Iterating through an array to check if all variables have a certain value – Game Development Stack Exchange

php – Weird array, get value, but get 1 letter or number back

so I have this array:

array(3) {
    (0) => array(15) {
        ("ID") => string(10)
        "1234567890" (0) => string(10)
        "1234567890" ("value1") => string(13)
        "lorem" (1) => string(6)
        "Ipsum" 
    }

I access the values using a for each loop:

foreach ($tests as $test)
        {       
            $character = $test('ID') . "  / " . $test('value1') . " / " . $test('value1')(1) 
        }

But now it prints : 1234567890 / lorem / lorem
with the (1) it prints: 1234567890 / lorem / I
It gets one letter for some reason.

I want to be able to print $character: 1234567890 / lorem / Ipsum.
My question is, why is this and how can I access the second value properly?

Porque eu não consigo comparar um array de BigDecimal com outro BigDecimal?

Para comparar eu preciso converter para algum tipo especifico ?

  • Erro que apareceu

inserir a descrição da imagem aqui

  • o ”Array_mediaVoltas” é um arrayList do tipo BigDecimal:

inserir a descrição da imagem aqui

unity – Get all images from peristent data path and save them to a Texture2D array

So i managed to make a working script that downloads images from firebase in this situation and saves them to Application.persistentDataPath. Now what i would like help in doing is getting all those images “*jpg” and assigning them to a Texture2D array for later use.

So far i have mananged to open one of those images by name and assign it to a single texture.

    public Texture2D image;

 private void Awake()
    {
        string dirname = "levelNature";
        string path = Application.persistentDataPath + "/" + dirname + "/" + "nameofImage.jpg";

        LoadSprite(fileName);
       
    }

    private void LoadSprite(string path)
    {
        if (string.IsNullOrEmpty(path)) 
            Debug.Log("null or empty");

        if (File.Exists(path))
        {
            byte() bytes = File.ReadAllBytes(path);
            Texture2D texture = new Texture2D(1024, 1024, TextureFormat.RGB24, false);
            texture.LoadImage(bytes);
            image = texture;
            Debug.Log("success");
        }
    }

With just one image i can assign it to a texture but since later on in the gameplay i’m using a texture2d array to assign those images to the gameplay , which now are set through the inspector , i would like to load all images in a particular folder to a Texture2D array which later on i will be using to show each image index in a specific level.

I did try it out like this but it isn’t successful.

    public Texture2D() source;

        var fileNames = Directory.GetFiles(Application.persistentDataPath + "/" + dirname + "/" + "*.jpg");

        source = new Texture2D(fileNames.Length);
        int index = 0;
        foreach (var fileName in fileNames)
        {
            source(index) = LoadSprite(fileName); // i get the error here that it cant convert void to texture2D
            index++;
        }

Hopefully once all images are loaded i could see in that array in the inspector all the images and then use that for the rest of the game. Thank you!

DreamProxies - Cheapest USA Elite Private Proxies 100 Private Proxies 200 Private Proxies 400 Private Proxies 1000 Private Proxies 2000 Private Proxies ExtraProxies.com - Buy Cheap Private Proxies Buy 50 Private Proxies Buy 100 Private Proxies Buy 200 Private Proxies Buy 500 Private Proxies Buy 1000 Private Proxies Buy 2000 Private Proxies ProxiesLive Proxies-free.com New Proxy Lists Every Day Proxies123