public CSimpleNode SearchNode(ListBox pList, string pInfo) { if (ItsEmpty(pList) == true) { pList.Items.Clear(); pList.Items.Add("The list is empty"); return(null); } else { pList.Items.Clear(); } work2 = inicio; while (work2.NextNode != null) { work2 = work2.NextNode; if (work2.Information == pInfo) { return(work2); } } return(null); }
public CSimpleLinkedList() { //Instanciamos el inicio. inicio = new CSimpleNode(); //Como es una lista vacia, el siguiente node esta vacío. inicio.NextNode = null; }
//Nos permite recorrer de forma secuencial a cada uno de los nodos. public void Transverse(ListBox pList) { pList.Items.Clear(); work = inicio; while (work.NextNode != null) { work = work.NextNode; string info = work.Information; pList.Items.Add(info); } }
private void btnSearchList_Click(object sender, EventArgs e) { if (txtName.Text.Length > 1) { CSimpleNode theNode = listStudent.SearchNode(lstStudent, txtName.Text); if (theNode != null) { lstStudent.Items.Add("[" + theNode.Information + "] was found."); } } else { MessageBox.Show("Please, enter a name."); } }
//Se ingresa el valor en el último nodo de la lista. public void Add(string pInformation) { //Iniciamos con el valor vacio de inicio. work = inicio; //Recorremos hasta el final para tener el último valor. while (work.NextNode != null) { work = work.NextNode; } //Instanciamos una variable de referencia. CSimpleNode temporary = new CSimpleNode(); //Ingresamos el valor ingresado por parámetro. temporary.Information = pInformation; //Finalizamos correctamente. temporary.NextNode = null; //Se ingresa el valor al último nodo encontrado con el recién creado. work.NextNode = temporary; }