/** * ntree_insert - Following the parent path, adds new node * @tree: Points to root of NTree node * @parents: An array of strings, shows path to new node * @data: New string to be stored * Description: The func adds a new node to ntree */ int ntree_insert(NTree **tree, char **parents, char *data) { List *list_node; if (*tree == NULL) { *tree = create_tree_node(data); return 0; } list_node = traverse_nodes(*tree, parents); if ( create_new_list(list_node, data, *tree) == NULL ) { return 1; } return 0; }
int main() { int choice,index,new_data; struct node *head; head = create_new_list(); printf("\n"); do { printf("Operations menu:\n"); printf("1. Insert a node.\n"); printf("2. Find a node.\n"); printf("3. Delete a node.\n"); printf("4. Display list.\n"); printf("5. Exit.\n"); printf("Enter your choice..: "); scanf("%d",&choice); switch(choice) { case 1 : printf("\nEnter the data and index of the new node\n"); printf("index : "); scanf("%d",&index); printf("data : "); scanf("%d",&new_data); insert_node(index, new_data, head); display_list(head); break; case 2 : printf("\nEnter the data to be searched : "); scanf("%d",&new_data); index = search_node(new_data, head); if (index == -1) printf("\nGiven data not found in the list.!!!\n\n"); else printf("\nPosition of the given data is... %d\n\n",index); break; case 3 : printf("\nEnter the data to be deleted : "); scanf("%d",&new_data); index = search_node(new_data, head); if (index == -1) printf("\nGiven data not found in the list.\n"); else del_node(index, head); display_list(head); break; case 4 : display_list(head); break; case 5 : break; default : printf("Please enter a valid choice !!!\n\n"); } } while (choice!=5); return 0; }