FUNZIONAAAAAAAAAH
This commit is contained in:
parent
9164a62f9e
commit
69f8fc5130
54
Program.cs
54
Program.cs
@ -4,6 +4,58 @@ class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine("Hello, World!");
|
||||
int[] array = new int [Dimensione()];
|
||||
InserimentoValoriArray(array);
|
||||
ScambioValoreMinimo(array);
|
||||
BubbleSort(array);
|
||||
}
|
||||
static int Dimensione(){
|
||||
int ritorno;
|
||||
do {
|
||||
Console.Write("Quanto grande deve essere l'array? ");
|
||||
ritorno = Convert.ToInt32(Console.ReadLine());
|
||||
if (ritorno <= 1) {
|
||||
Console.WriteLine("L'array deve avere una dimensione maggiore di uno");
|
||||
}
|
||||
}
|
||||
while (ritorno <= 1);
|
||||
return ritorno;
|
||||
}
|
||||
static void InserimentoValoriArray(int[] p_array){
|
||||
for (int i=0; i<p_array.Length;i++){
|
||||
Console.Write("Inserire il " + (i + 1) + "° numero: ");
|
||||
p_array[i] = Convert.ToInt32(Console.ReadLine());
|
||||
}
|
||||
}
|
||||
static void ScambioValoreMinimo(int[] p_array){
|
||||
int min = Int32.MaxValue, iMinimo=0, temp;
|
||||
//trovo il valore più piccolo in tutto l'array
|
||||
for(int i=0; i<p_array.Length; i++){
|
||||
if(p_array[i] < min){
|
||||
min = p_array[i];
|
||||
iMinimo = i;
|
||||
}
|
||||
}
|
||||
//scambio il valore più piccolo con quello alla prima posizione
|
||||
temp = p_array[0];
|
||||
p_array[0] = p_array[iMinimo];
|
||||
p_array[iMinimo] = temp;
|
||||
}
|
||||
static void BubbleSort(int[] p_array) {
|
||||
int temp, numeroScambi=0;
|
||||
|
||||
for (int i = 0; i < p_array.Length; i++) {//per ogni cella dell'array
|
||||
|
||||
for (int j = 0; j < p_array.Length - 1 - i; j++) {//per ogni cella dell'array, con il limite massimo che continua a diminuire in proporzione a i
|
||||
|
||||
if (p_array[j] > p_array[j + 1]) {//se la cella a sinistra è maggiore di quella a destra
|
||||
numeroScambi++;//conto il numero di scambi che effettuo (che coincide con il numero di volte in cui la condizione qui sopra sia vera)
|
||||
temp = p_array[j]; //memorizzo la cella da cambiare (a sinistra)
|
||||
p_array[j] = p_array[j + 1]; //sovrascrivo la cella a sinistra con quella a destra (la maggiore)
|
||||
p_array[j + 1] = temp;//sovrascrivo la cella a destra con il valore originale di quella a sinistra
|
||||
}
|
||||
}
|
||||
}
|
||||
Console.WriteLine("Numero scambi: " + numeroScambi);
|
||||
}
|
||||
}
|
||||
|
||||
BIN
bin/Debug/net9.0/sorting_proximity
Executable file
BIN
bin/Debug/net9.0/sorting_proximity
Executable file
Binary file not shown.
23
bin/Debug/net9.0/sorting_proximity.deps.json
Normal file
23
bin/Debug/net9.0/sorting_proximity.deps.json
Normal file
@ -0,0 +1,23 @@
|
||||
{
|
||||
"runtimeTarget": {
|
||||
"name": ".NETCoreApp,Version=v9.0",
|
||||
"signature": ""
|
||||
},
|
||||
"compilationOptions": {},
|
||||
"targets": {
|
||||
".NETCoreApp,Version=v9.0": {
|
||||
"sorting_proximity/1.0.0": {
|
||||
"runtime": {
|
||||
"sorting_proximity.dll": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"libraries": {
|
||||
"sorting_proximity/1.0.0": {
|
||||
"type": "project",
|
||||
"serviceable": false,
|
||||
"sha512": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
bin/Debug/net9.0/sorting_proximity.dll
Normal file
BIN
bin/Debug/net9.0/sorting_proximity.dll
Normal file
Binary file not shown.
BIN
bin/Debug/net9.0/sorting_proximity.pdb
Normal file
BIN
bin/Debug/net9.0/sorting_proximity.pdb
Normal file
Binary file not shown.
12
bin/Debug/net9.0/sorting_proximity.runtimeconfig.json
Normal file
12
bin/Debug/net9.0/sorting_proximity.runtimeconfig.json
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"runtimeOptions": {
|
||||
"tfm": "net9.0",
|
||||
"framework": {
|
||||
"name": "Microsoft.NETCore.App",
|
||||
"version": "9.0.0"
|
||||
},
|
||||
"configProperties": {
|
||||
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,4 @@
|
||||
// <autogenerated />
|
||||
using System;
|
||||
using System.Reflection;
|
||||
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v9.0", FrameworkDisplayName = ".NET 9.0")]
|
||||
BIN
obj/Debug/net9.0/apphost
Executable file
BIN
obj/Debug/net9.0/apphost
Executable file
Binary file not shown.
BIN
obj/Debug/net9.0/ref/sorting_proximity.dll
Normal file
BIN
obj/Debug/net9.0/ref/sorting_proximity.dll
Normal file
Binary file not shown.
BIN
obj/Debug/net9.0/refint/sorting_proximity.dll
Normal file
BIN
obj/Debug/net9.0/refint/sorting_proximity.dll
Normal file
Binary file not shown.
22
obj/Debug/net9.0/sorting_proximity.AssemblyInfo.cs
Normal file
22
obj/Debug/net9.0/sorting_proximity.AssemblyInfo.cs
Normal file
@ -0,0 +1,22 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
[assembly: System.Reflection.AssemblyCompanyAttribute("sorting_proximity")]
|
||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+9164a62f9e443a5a7ccbe17b05930889bd2c2776")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("sorting_proximity")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("sorting_proximity")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
||||
// Generated by the MSBuild WriteCodeFragment class.
|
||||
|
||||
@ -0,0 +1 @@
|
||||
c22826eab3b2e5493e6d270aec65243f5dd384d61e47a0c286073aa07b67762a
|
||||
@ -0,0 +1,15 @@
|
||||
is_global = true
|
||||
build_property.TargetFramework = net9.0
|
||||
build_property.TargetPlatformMinVersion =
|
||||
build_property.UsingMicrosoftNETSdkWeb =
|
||||
build_property.ProjectTypeGuids =
|
||||
build_property.InvariantGlobalization =
|
||||
build_property.PlatformNeutralAssembly =
|
||||
build_property.EnforceExtendedAnalyzerRules =
|
||||
build_property._SupportedPlatformList = Linux,macOS,Windows
|
||||
build_property.RootNamespace = sorting_proximity
|
||||
build_property.ProjectDir = /home/Verde/git/sorting_proximity/
|
||||
build_property.EnableComHosting =
|
||||
build_property.EnableGeneratedComInterfaceComImportInterop =
|
||||
build_property.EffectiveAnalysisLevelStyle = 9.0
|
||||
build_property.EnableCodeStyleSeverity =
|
||||
8
obj/Debug/net9.0/sorting_proximity.GlobalUsings.g.cs
Normal file
8
obj/Debug/net9.0/sorting_proximity.GlobalUsings.g.cs
Normal file
@ -0,0 +1,8 @@
|
||||
// <auto-generated/>
|
||||
global using global::System;
|
||||
global using global::System.Collections.Generic;
|
||||
global using global::System.IO;
|
||||
global using global::System.Linq;
|
||||
global using global::System.Net.Http;
|
||||
global using global::System.Threading;
|
||||
global using global::System.Threading.Tasks;
|
||||
BIN
obj/Debug/net9.0/sorting_proximity.assets.cache
Normal file
BIN
obj/Debug/net9.0/sorting_proximity.assets.cache
Normal file
Binary file not shown.
@ -0,0 +1 @@
|
||||
23cd7bfe049ffd352513a5e6e4865bba544b1843494ccf0ca4f5ecdd6fb49904
|
||||
@ -0,0 +1,14 @@
|
||||
/home/Verde/git/sorting_proximity/bin/Debug/net9.0/sorting_proximity
|
||||
/home/Verde/git/sorting_proximity/bin/Debug/net9.0/sorting_proximity.deps.json
|
||||
/home/Verde/git/sorting_proximity/bin/Debug/net9.0/sorting_proximity.runtimeconfig.json
|
||||
/home/Verde/git/sorting_proximity/bin/Debug/net9.0/sorting_proximity.dll
|
||||
/home/Verde/git/sorting_proximity/bin/Debug/net9.0/sorting_proximity.pdb
|
||||
/home/Verde/git/sorting_proximity/obj/Debug/net9.0/sorting_proximity.GeneratedMSBuildEditorConfig.editorconfig
|
||||
/home/Verde/git/sorting_proximity/obj/Debug/net9.0/sorting_proximity.AssemblyInfoInputs.cache
|
||||
/home/Verde/git/sorting_proximity/obj/Debug/net9.0/sorting_proximity.AssemblyInfo.cs
|
||||
/home/Verde/git/sorting_proximity/obj/Debug/net9.0/sorting_proximity.csproj.CoreCompileInputs.cache
|
||||
/home/Verde/git/sorting_proximity/obj/Debug/net9.0/sorting_proximity.dll
|
||||
/home/Verde/git/sorting_proximity/obj/Debug/net9.0/refint/sorting_proximity.dll
|
||||
/home/Verde/git/sorting_proximity/obj/Debug/net9.0/sorting_proximity.pdb
|
||||
/home/Verde/git/sorting_proximity/obj/Debug/net9.0/sorting_proximity.genruntimeconfig.cache
|
||||
/home/Verde/git/sorting_proximity/obj/Debug/net9.0/ref/sorting_proximity.dll
|
||||
BIN
obj/Debug/net9.0/sorting_proximity.dll
Normal file
BIN
obj/Debug/net9.0/sorting_proximity.dll
Normal file
Binary file not shown.
@ -0,0 +1 @@
|
||||
24eb914aab136ea75fd7346a673f999dd04017fa638348224da58e591929b2ec
|
||||
BIN
obj/Debug/net9.0/sorting_proximity.pdb
Normal file
BIN
obj/Debug/net9.0/sorting_proximity.pdb
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user