public List <lista> listaCompletatotal() { lista l; List <lista> listaCompleta = new List <lista>(); l = new lista(); l.codigo = 111; l.embalagem = "UN"; l.qtd = 1; listaCompleta.Add(l); l = new lista(); l.codigo = 112; l.embalagem = "CX"; l.qtd = 1; listaCompleta.Add(l); l = new lista(); l.codigo = 113; l.embalagem = "PT"; l.qtd = 1; listaCompleta.Add(l); return(listaCompleta); }
public IEnumerable <lista> getLista(string tabla, string nombreCampo, string nombreValor, string campoRetorno, string idUsuario) { IList <lista> listaClientes = new List <lista>(); DataSet ds = Conexion.ejecutar_select("sp_generico_lst2 '" + tabla + "','" + nombreCampo + "','" + nombreValor + "','" + campoRetorno + "'"); lista cli = null; if (ds.Tables[0].Rows.Count > 0) { for (int i = 0; i <= ds.Tables[0].Rows.Count - 1; i++) { cli = new lista(); cli.idClieCliente = Convert.ToInt32(ds.Tables[0].Rows[i][1].ToString()); cli.rut = ds.Tables[0].Rows[i][2].ToString(); cli.nombre = ds.Tables[0].Rows[i][3].ToString(); cli.apellido = ds.Tables[0].Rows[i][4].ToString(); cli.razonSocial = ds.Tables[0].Rows[i][5].ToString(); listaClientes.Add(cli); } } else { } return(listaClientes); }
static void Main(string[] args) { lista li = new lista(); li.insertar(1); li.insertar(2); li.insertar(3); li.recorrerlista(); }
public static void main(String[] args) { lista lst = new lista(); lst.remover(8); lst.inserir(15); lst.inserir(8); lst.imp(); lst.remover(8); lst.imp(); }
static void Main(string [] arg) { lista l = new lista(); l.insertarnodo(); l.insertarnodo(); l.insertarnodo(); l.insertarnodo(); l.insertarnodo(); l.insertarnodo(); l.insertarnodo(); Console.WriteLine("\n las lista de nodos ingresada es: \n"); l.desplegarlista(); }
private void bRun_Click(object sender, EventArgs e) { try { int w = int.Parse(tbMochila.Text); int aux = 0; while (dgItens.Rows[1].Cells[aux].Value != null) { aux++; } itens[] n = new itens[aux + 1]; n[0].p = 0; n[0].v = 0; for (int i = 1; i < aux + 1; i++) { n[i].p = int.Parse(dgItens.Rows[1].Cells[i-1].Value.ToString()); n[i].v = int.Parse(dgItens.Rows[2].Cells[i-1].Value.ToString()); } Stopwatch stopwatch = new Stopwatch(); bRun.Text = "Rodando..."; bRun.Enabled = false; if (rbMochilaD.Checked) { tbVD.Text = ""; tbPD.Text = ""; this.Refresh(); lista[] Lista = new lista[1]; Lista[0].i = 0; Lista[0].a = 0; stopwatch.Start(); itens q = Mochila_0_1_Dinâmico(n, w, ref Lista); stopwatch.Stop(); tbVD.Text = q.v.ToString(); tbPD.Text = q.p.ToString(); Print_Mochila_Itens(Lista); } bRun.Enabled = true; bRun.Text = "&Rodar algoritmo"; } catch (Exception erro) { MessageBox.Show(erro.Message, "Erro"); } }
public ActionResult Historia(lista lista) { var historia = db.historia.Include(h => h.paciente); if (lista.paciente != 0) { historia = historia.Where(h => h.his_paciente == lista.paciente); } if (!String.IsNullOrEmpty(lista.fecha)) { historia = historia.Where(h => h.his_fecha == lista.fecha); } historia = historia.Where(h => h.his_tipo == 1); //ViewBag.paciente = lista.paciente +" "+lista.fecha+" "+lista.tipo; return(PartialView(historia.ToList())); }
public List <lista> Origen(string playlist, int ID) { List <lista> datos = new List <lista>(); lista f = new lista(); f.nombre = "Ben Jadusable - Ben Drowned"; f.url = "https://mkef01.000webhostapp.com/Song%20of%20healing%20%20Extended%20%20Reversed.mp3"; datos.Add(f); lista d = new lista(); d.nombre = "A Day in the Life - The Beatles"; d.url = "https://mkef01.000webhostapp.com/13%20-%20A%20Day%20In%20The%20Life.flac"; datos.Add(d); lista s = new lista(); s.nombre = "Saxon - Crusader Prelude"; s.url = "https://s3-us-west-2.amazonaws.com/allmetalmixtapes/Saxon%20-%201984%20-%20Crusader/01%20-%20Crusader%20Prelude.mp3"; datos.Add(s); return(datos); }
private void listaToolStripMenuItem_Click(object sender, EventArgs e) { lista f5 = new lista(); f5.Show(); }
private void bRun_Click(object sender, EventArgs e) { try { //Lê o peso máximo da mochila int w = int.Parse(tbMochila.Text); //Descobre a quantidade de itens int aux = 0; while (dgItens.Rows[1].Cells[aux].Value != null) { aux++; } //Cria vetor de estrutura com itens itens[] n = new itens[aux + 1]; //Preenche o vetor com os pesos e valores de 0 a n n[0].p = 0; n[0].v = 0; for (int i = 1; i < aux + 1; i++) { n[i].p = int.Parse(dgItens.Rows[1].Cells[i - 1].Value.ToString()); n[i].v = int.Parse(dgItens.Rows[2].Cells[i - 1].Value.ToString()); } //Cria um Stopwatch para medir o tempo Stopwatch stopwatch = new Stopwatch(); //Desabilita o botão Run e troca o texto bRun.Text = "Rodando..."; bRun.Enabled = false; //Se selecionou algoritmo Cut-Rod if (rbMochilaFB.Checked) { tbVFB.Text = ""; tbPFB.Text = ""; tbTFB.Text = ""; this.Refresh(); stopwatch.Start(); stopwatch.Stop(); tbTFB.Text = stopwatch.ElapsedMilliseconds.ToString(); } //Se selecionou algoritmo Extended-Botton-Up-Cut-Rod if (rbMochilaD.Checked) { tbVD.Text = ""; tbPD.Text = ""; tbTD.Text = ""; this.Refresh(); lista[] Lista = new lista[1]; //Cria uma nova lista para receber os itens Lista[0].i = 0; Lista[0].a = 0; stopwatch.Start(); itens q = Mochila_0_1_Dinâmico(n, w, ref Lista); stopwatch.Stop(); tbVD.Text = q.v.ToString(); tbPD.Text = q.p.ToString(); tbTD.Text = stopwatch.ElapsedMilliseconds.ToString(); //Escrever o método para o print dos itens da lista Print_Mochila_Itens(Lista); } //Habilita o botão Run e troca o texto bRun.Enabled = true; bRun.Text = "&Rodar algoritmo"; } catch (Exception erro) { MessageBox.Show(erro.Message, "Erro"); } }
/// <summary> /// Coloca na mochila o maior valor possível /// usando programação dinâmica /// </summary> /// <param name="n">lista de itens com valor e peso começa no item 0 nulo</param> /// <param name="w">peso máximo da mochila</param> /// <param name="Lista">lista com itens selecionados e anterior saída por referência</param> /// <returns>peso e valor final da mochila</returns> private itens Mochila_0_1_Dinâmico(itens[] n, int w, ref lista[] Lista) { itens resposta; resposta.v = 0; resposta.p = 0; int c = n.Length; itens[] mochila = new itens[w + 1]; mochila[0].p = 0; mochila[0].v = 0; Lista = new lista[w + 1]; Lista[0].i = 0; Lista[0].a = 0; bool[] usado = new bool[c]; for (int i = 0; i < c; i++) { usado[i] = false; } //Para cada um dos pesos for (int peso = 1; peso <= w; peso++) { //Mochila começa com as características da mochila de peso uma unidade inferior mochila[peso].p = mochila[peso - 1].p; mochila[peso].v = mochila[peso - 1].v; //Lista começa com item 0 e peso uma unidade inferior Lista[peso].i = 0; Lista[peso].a = peso - 1; //Para cada um dos itens for (int item = 1; item < c; item++) { //Se o peso atual é maior que o peso do item if (peso >= n[item].p) { //Se o peso atual é >= que o peso de uma solução ótima anterior + o peso do item atual if (peso >= mochila[peso - n[item].p].p + n[item].p) { //Se o valor para o peso atual é < que o valor de uma solução ótima anterior + o valor do item atual if (mochila[peso].v < mochila[peso - n[item].p].v + n[item].v) { //Busca em profundidade nos itens da subsolução ótima bool ok = true; int busca = peso - n[item].p; //Item anterior while (busca > 0) { int itemAnt = Lista[busca].i; //Se o item anterior á nulo if (itemAnt == 0) { //busca--; //Decrementa o peso da busca //continue; //Pula para próxima iteração } //Se o item anterior é igual ao item atual if (itemAnt == item) { ok = false; //Não pode usar este item break; //Quebra o laço } //busca -= n[itemAnt].p; //Aprofunda a busca decrementado do peso do item anterior busca = Lista[busca].a; } //Se o item atual é diferente dos itens das subsoluções ótimas anteriores if (ok == true) { //Atualiza a solução ótima atual mochila[peso].v = mochila[peso - n[item].p].v + n[item].v; mochila[peso].p = mochila[peso - n[item].p].p + n[item].p; //Grava o item e anterior selecionado para solução ótima com peso atual Lista[peso].i = item; Lista[peso].a = peso - n[item].p; } } } } } } resposta.v = mochila[w].v; resposta.p = mochila[w].p; return(resposta); }
private void estadisticasToolStripMenuItem_Click(object sender, EventArgs e) { lista f = new lista(_db); f.Show(); }
private void Print_Mochila_Itens(lista[] Lista) { tbPrint.Text = ""; int c = Lista.Length - 1; while (c > 0) { if (Lista[c].i != 0) { tbPrint.Text += Lista[c].i.ToString() + ", "; } c = Lista[c].a; } if (tbPrint.Text.Length > 2) { tbPrint.Text = tbPrint.Text.Substring(0, tbPrint.Text.Length - 2); } dgDebug.ColumnCount = Lista.Length; for (int i = 0; i < dgDebug.ColumnCount; i++) { dgDebug.Rows[0].Cells[i].Value = null; dgDebug.Rows[1].Cells[i].Value = null; dgDebug.Rows[2].Cells[i].Value = null; } for (int i = 0; i < Lista.Length; i++) { dgDebug.Rows[0].Cells[i].Value = i.ToString(); dgDebug.Rows[1].Cells[i].Value = Lista[i].i.ToString(); dgDebug.Rows[2].Cells[i].Value = Lista[i].a.ToString(); } int solução = Lista.Length - 1; while(solução > 0) { dgDebug.Rows[1].Cells[solução].Value = "* " + dgDebug.Rows[1].Cells[solução].Value; solução = int.Parse(dgDebug.Rows[2].Cells[solução].Value.ToString()); } }
private itens Mochila_0_1_Dinâmico(itens[] n, int w, ref lista[] Lista) { itens resposta; resposta.v = 0; resposta.p = 0; int c = n.Length; itens[] mochila = new itens[w + 1]; mochila[0].p = 0; mochila[0].v = 0; Lista = new lista[w + 1]; Lista[0].i = 0; Lista[0].a = 0; bool[] usado = new bool[c]; for (int i = 0; i < c; i++) { usado[i] = false; } for (int peso = 1; peso <= w; peso++) { mochila[peso].p = mochila[peso-1].p; mochila[peso].v = mochila[peso-1].v; Lista[peso].i = 0; Lista[peso].a = peso-1; for (int item = 1; item < c; item++) { if (peso >= n[item].p) { if (peso >= mochila[peso - n[item].p].p + n[item].p) { if (mochila[peso].v < mochila[peso - n[item].p].v + n[item].v) { bool ok = true; int busca = peso - n[item].p; while(busca > 0) { int itemAnt = Lista[busca].i; if (itemAnt == 0) { } if(itemAnt == item) { ok = false; break; } busca = Lista[busca].a; } if (ok == true) { mochila[peso].v = mochila[peso - n[item].p].v + n[item].v; mochila[peso].p = mochila[peso - n[item].p].p + n[item].p; Lista[peso].i = item; Lista[peso].a = peso - n[item].p; } } } } } } resposta.v = mochila[w].v; resposta.p = mochila[w].p; return resposta; }
static void Main(string[] args) { int opc; bool ComprobadorMenu; string caracter; lista listoidea = new lista(); do { ComprobadorMenu = false; caracter = ""; Console.WriteLine("*****************Lista de caracteres*****************"); Console.WriteLine("* *"); Console.WriteLine("* 1-insertar valor *"); Console.WriteLine("* 2-Eliminar valor *"); Console.WriteLine("* 3-Ver lista *"); Console.WriteLine("* 4-Total de elementos *"); Console.WriteLine("* 5-Salir *"); Console.WriteLine("* *"); Console.WriteLine("*****************************************************"); Console.WriteLine("\nIngrese la accion a realizar: "); opc = int.Parse(Console.ReadLine()); switch (opc) { case 1: Console.Clear(); Console.WriteLine("ingrese el nuevo valor:"); caracter = Console.ReadLine(); listoidea.insercion(caracter); Console.WriteLine("\nCaracter insertado"); Console.WriteLine("...\nPresione cualquier tecla para volver al menu"); Console.ReadKey(); Console.Clear(); ComprobadorMenu = true; break; case 2: Console.Clear(); Console.WriteLine("ingrese dato a eliminar:"); caracter = Console.ReadLine(); listoidea.eliminardato(caracter); Console.WriteLine("...\nPresione cualquier tecla para volver al menu"); Console.ReadKey(); Console.Clear(); ComprobadorMenu = true; break; case 3: Console.Clear(); Console.WriteLine("LISTOIDEA: "); listoidea.mostrar(); Console.WriteLine("\nPresione cualquier tecla para volver al menu"); Console.ReadKey(); ComprobadorMenu = true; Console.Clear(); break; case 4: Console.Clear(); listoidea.contar(); Console.WriteLine("...\nPresione cualquier tecla para volver al menu"); Console.ReadKey(); ComprobadorMenu = true; Console.Clear(); break; case 5: Console.Clear(); Console.WriteLine("Gracias!"); Console.ReadKey(); Console.Clear(); break; default: Console.Clear(); Console.WriteLine("ingrese un dato valido"); Console.ReadKey(); Console.Clear(); ComprobadorMenu = true; break; } } while (ComprobadorMenu); }