Portato da Flowgorithm (con menù aggiunto)
This commit is contained in:
parent
c817978ad7
commit
46387e301a
113
Program.cs
113
Program.cs
@ -1,9 +1,112 @@
|
|||||||
namespace insertion_sort;
|
namespace insertion_sort;
|
||||||
|
|
||||||
class Program
|
class Program {
|
||||||
{
|
const int dimensione = 10;
|
||||||
static void Main(string[] args)
|
static void Main(string[] args) {
|
||||||
{
|
Console.Clear();
|
||||||
Console.WriteLine("Hello, World!");
|
//dichiarazione e inizializzazione variabili
|
||||||
|
int scelta;
|
||||||
|
int[] array = null;
|
||||||
|
bool opzione1 = false, opzione3 = false;
|
||||||
|
|
||||||
|
//menu
|
||||||
|
do {
|
||||||
|
Console.WriteLine("Scegliere un'opzione:");
|
||||||
|
Console.WriteLine("1. Crea array casuale");
|
||||||
|
Console.WriteLine("2. Mostra array casuale");
|
||||||
|
Console.WriteLine("3. Riordina array casuale");
|
||||||
|
Console.WriteLine("4. Mostra array ordinato");
|
||||||
|
Console.WriteLine("0. Esci");
|
||||||
|
Console.Write("Scelta: ");
|
||||||
|
scelta = Convert.ToInt32(Console.ReadLine());
|
||||||
|
|
||||||
|
|
||||||
|
switch (scelta) {
|
||||||
|
case 0:
|
||||||
|
Console.Clear();
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
Console.Clear();
|
||||||
|
array = CreaArrayCasuale();
|
||||||
|
opzione1 = true;
|
||||||
|
Pausa();
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
Console.Clear();
|
||||||
|
if (opzione1) {
|
||||||
|
StampaArray(array);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Console.WriteLine("Bisogna creare l'array casuale prima di mostrarlo");
|
||||||
|
}
|
||||||
|
Pausa();
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
Console.Clear();
|
||||||
|
if (opzione1) {
|
||||||
|
OrdinaArray(array);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Console.WriteLine("Bisogna creare l'array casuale prima di ordinarlo");
|
||||||
|
}
|
||||||
|
opzione3 = true;
|
||||||
|
Pausa();
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
Console.Clear();
|
||||||
|
if (opzione3) {
|
||||||
|
StampaArray(array);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Console.WriteLine("Bisogna creare l'array casuale prima di mostrarlo");
|
||||||
|
}
|
||||||
|
Pausa();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Console.WriteLine("Errore: scelta non valida");
|
||||||
|
Pausa();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (scelta != 0);
|
||||||
|
}
|
||||||
|
static void Pausa() {
|
||||||
|
Console.WriteLine("Premere un tasto per continuare. . .");
|
||||||
|
Console.ReadKey();
|
||||||
|
Console.Clear();
|
||||||
|
}
|
||||||
|
static void StampaArray(int[] p_insieme) {
|
||||||
|
for (int j = 0; j < p_insieme.Length; j++) {
|
||||||
|
Console.WriteLine("Elemento " + j + ": " + p_insieme[j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
static int[] CreaArrayCasuale() {
|
||||||
|
//dichiarazione e inizializzazione variabili
|
||||||
|
const int maxLength = 10;
|
||||||
|
Random caso = new Random();
|
||||||
|
int[] ritorno = new int[dimensione];
|
||||||
|
|
||||||
|
for (int i = 0; i < dimensione; i++) {
|
||||||
|
ritorno[i] = caso.Next(maxLength);//per ogni posizione di ritorno assegno un valore a caso (metodo Random.Next)
|
||||||
|
}
|
||||||
|
return ritorno;
|
||||||
|
}
|
||||||
|
static void OrdinaArray(int[] p_array) {
|
||||||
|
int k, temp;
|
||||||
|
|
||||||
|
for (int i = 0; i < dimensione; i++) {
|
||||||
|
k = dimensione - i;
|
||||||
|
do {
|
||||||
|
if (!(k == dimensione || k < 0 || k - 1 < 0)) {
|
||||||
|
if (p_array[k] < p_array[k - 1]) {
|
||||||
|
temp = p_array[k];
|
||||||
|
p_array[k] = p_array[k - 1];
|
||||||
|
p_array[k - 1] = temp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
k--;
|
||||||
|
}
|
||||||
|
while (k > 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
BIN
bin/Debug/net9.0/insertion_sort
Executable file
BIN
bin/Debug/net9.0/insertion_sort
Executable file
Binary file not shown.
23
bin/Debug/net9.0/insertion_sort.deps.json
Normal file
23
bin/Debug/net9.0/insertion_sort.deps.json
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"runtimeTarget": {
|
||||||
|
"name": ".NETCoreApp,Version=v9.0",
|
||||||
|
"signature": ""
|
||||||
|
},
|
||||||
|
"compilationOptions": {},
|
||||||
|
"targets": {
|
||||||
|
".NETCoreApp,Version=v9.0": {
|
||||||
|
"insertion_sort/1.0.0": {
|
||||||
|
"runtime": {
|
||||||
|
"insertion_sort.dll": {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"libraries": {
|
||||||
|
"insertion_sort/1.0.0": {
|
||||||
|
"type": "project",
|
||||||
|
"serviceable": false,
|
||||||
|
"sha512": ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
bin/Debug/net9.0/insertion_sort.dll
Normal file
BIN
bin/Debug/net9.0/insertion_sort.dll
Normal file
Binary file not shown.
BIN
bin/Debug/net9.0/insertion_sort.pdb
Normal file
BIN
bin/Debug/net9.0/insertion_sort.pdb
Normal file
Binary file not shown.
12
bin/Debug/net9.0/insertion_sort.runtimeconfig.json
Normal file
12
bin/Debug/net9.0/insertion_sort.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.
22
obj/Debug/net9.0/insertion_sort.AssemblyInfo.cs
Normal file
22
obj/Debug/net9.0/insertion_sort.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("insertion_sort")]
|
||||||
|
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||||
|
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||||
|
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+c817978ad78c3196c23720330f72d79a29843579")]
|
||||||
|
[assembly: System.Reflection.AssemblyProductAttribute("insertion_sort")]
|
||||||
|
[assembly: System.Reflection.AssemblyTitleAttribute("insertion_sort")]
|
||||||
|
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||||
|
|
||||||
|
// Generated by the MSBuild WriteCodeFragment class.
|
||||||
|
|
||||||
1
obj/Debug/net9.0/insertion_sort.AssemblyInfoInputs.cache
Normal file
1
obj/Debug/net9.0/insertion_sort.AssemblyInfoInputs.cache
Normal file
@ -0,0 +1 @@
|
|||||||
|
b5ba8fdce8a72d37bd1d20286034b268b3dace8a8a33aee089a01308b93f408b
|
||||||
@ -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 = insertion_sort
|
||||||
|
build_property.ProjectDir = /home/Verde/git/insertion_sort/
|
||||||
|
build_property.EnableComHosting =
|
||||||
|
build_property.EnableGeneratedComInterfaceComImportInterop =
|
||||||
|
build_property.EffectiveAnalysisLevelStyle = 9.0
|
||||||
|
build_property.EnableCodeStyleSeverity =
|
||||||
8
obj/Debug/net9.0/insertion_sort.GlobalUsings.g.cs
Normal file
8
obj/Debug/net9.0/insertion_sort.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/insertion_sort.assets.cache
Normal file
BIN
obj/Debug/net9.0/insertion_sort.assets.cache
Normal file
Binary file not shown.
@ -0,0 +1 @@
|
|||||||
|
5d2d7758d30a62e9cd616559526dd02de488d308f765edfb9af2cc4bfb50ea08
|
||||||
14
obj/Debug/net9.0/insertion_sort.csproj.FileListAbsolute.txt
Normal file
14
obj/Debug/net9.0/insertion_sort.csproj.FileListAbsolute.txt
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
/home/Verde/git/insertion_sort/bin/Debug/net9.0/insertion_sort
|
||||||
|
/home/Verde/git/insertion_sort/bin/Debug/net9.0/insertion_sort.deps.json
|
||||||
|
/home/Verde/git/insertion_sort/bin/Debug/net9.0/insertion_sort.runtimeconfig.json
|
||||||
|
/home/Verde/git/insertion_sort/bin/Debug/net9.0/insertion_sort.dll
|
||||||
|
/home/Verde/git/insertion_sort/bin/Debug/net9.0/insertion_sort.pdb
|
||||||
|
/home/Verde/git/insertion_sort/obj/Debug/net9.0/insertion_sort.GeneratedMSBuildEditorConfig.editorconfig
|
||||||
|
/home/Verde/git/insertion_sort/obj/Debug/net9.0/insertion_sort.AssemblyInfoInputs.cache
|
||||||
|
/home/Verde/git/insertion_sort/obj/Debug/net9.0/insertion_sort.AssemblyInfo.cs
|
||||||
|
/home/Verde/git/insertion_sort/obj/Debug/net9.0/insertion_sort.csproj.CoreCompileInputs.cache
|
||||||
|
/home/Verde/git/insertion_sort/obj/Debug/net9.0/insertion_sort.dll
|
||||||
|
/home/Verde/git/insertion_sort/obj/Debug/net9.0/refint/insertion_sort.dll
|
||||||
|
/home/Verde/git/insertion_sort/obj/Debug/net9.0/insertion_sort.pdb
|
||||||
|
/home/Verde/git/insertion_sort/obj/Debug/net9.0/insertion_sort.genruntimeconfig.cache
|
||||||
|
/home/Verde/git/insertion_sort/obj/Debug/net9.0/ref/insertion_sort.dll
|
||||||
BIN
obj/Debug/net9.0/insertion_sort.dll
Normal file
BIN
obj/Debug/net9.0/insertion_sort.dll
Normal file
Binary file not shown.
1
obj/Debug/net9.0/insertion_sort.genruntimeconfig.cache
Normal file
1
obj/Debug/net9.0/insertion_sort.genruntimeconfig.cache
Normal file
@ -0,0 +1 @@
|
|||||||
|
31066dd5f2be3208e0da652785065381222bfa0415951f3abc35c1e96237a265
|
||||||
BIN
obj/Debug/net9.0/insertion_sort.pdb
Normal file
BIN
obj/Debug/net9.0/insertion_sort.pdb
Normal file
Binary file not shown.
BIN
obj/Debug/net9.0/ref/insertion_sort.dll
Normal file
BIN
obj/Debug/net9.0/ref/insertion_sort.dll
Normal file
Binary file not shown.
BIN
obj/Debug/net9.0/refint/insertion_sort.dll
Normal file
BIN
obj/Debug/net9.0/refint/insertion_sort.dll
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user