static void create_node(linkedList pList) { bool returnVal = true; int list_returnval = 0; string command; int key = 0; //ask user for input Console.Write("Enter Key Value:"); command = Console.ReadLine(); returnVal = Int32.TryParse(command, out key); //check to see if number is valid if (returnVal == false) { Console.WriteLine("ERROR: Invalid input, enter number only!"); return; } //otherwise, create new node list_returnval = (int)pList.create_node(key); //see if the node was created if (list_returnval == (int)linkedList_return.CREATE_FAILED_DUPLICATE_KEY) { Console.WriteLine("ERROR: Could not create node, duplicate key found"); } else { Console.WriteLine("Node created successfully!"); } }
static void delete_node(linkedList pList) { bool returnVal = true; int list_returnval = 0; string command; int key = 0; //ask user for input Console.Write("Enter Key Value:"); command = Console.ReadLine(); returnVal = Int32.TryParse(command, out key); //check to see if number is valid if (returnVal == false) { Console.WriteLine("ERROR: Invalid input, enter number only!"); return; } //otherwise, delete node list_returnval = (int)pList.delete_node(key); //see if the node was deleted if (list_returnval == (int)linkedList_return.DELETE_FAILED_KEY_NOT_FOUND) { Console.WriteLine("ERROR: Could not delete node, node does not exist"); } else { Console.WriteLine("Node deleted"); } }
static void Main(string[] args) { int shutdown = 0; string command; Console.WriteLine("Initialising Empty Linked List..."); //initialise the linked list linkedList pList = new linkedList(); //get user input on what they want to do print_help(); while (shutdown != (int)return_code.SHUTDOWN) { Console.Write("#Linked_List Controller > "); //get user input command = Console.ReadLine(); //see what the user wants to do switch(command) { case "p": case "P": //print out the contents of the linked list pList.print_list(); break; case "i": case "I": create_node(pList); break; case "d": case "D": delete_node(pList); break; case "s": case "S": search_node(pList); break; case "q": case "Q": shutdown = (int)return_code.SHUTDOWN; break; case "h": case "H": print_help(); break; default: Console.WriteLine("Invalid input, type 'h' for help."); break; } } }
static void search_node(linkedList pList) { linkedList.default_node list_returnval = null; bool returnVal = true; string command; int key = 0; //ask user for input Console.Write("Enter Key Value:"); command = Console.ReadLine(); returnVal = Int32.TryParse(command, out key); //check to see if number is valid if (returnVal == false) { Console.WriteLine("ERROR: Invalid input, enter number only!"); return; } //otherwise, search for the node list_returnval = pList.find_node(key); //see if the node exists if (list_returnval == null) { Console.WriteLine("Node " + key + " Does not Exist"); } else { Console.WriteLine("Node " + key + " found!"); } }