Commit f2097af6 authored by Liam E. Roeth's avatar Liam E. Roeth

main.c working

parent d8f7825d
......@@ -10,7 +10,7 @@ void print_node_at(NODE *head, int pos){
for (int i = 0; i<pos; i++){
currentNode = currentNode->next;
}
printf("The data at index %d is: %d", pos, currentNode->data);
printf("The data at index %d is: %d\n", pos, currentNode->data);
}
void print_node(NODE *head){
......@@ -31,14 +31,13 @@ void print_list(NODE *head){
}
}
NODE_ERR psearch(NODE *head, datatype data){
printf("Searching list for: %d", data);
printf("Searching list for: %d\n", data);
NODE_ERR node = search(head, data);
if(node.node != NULL)
printf("Location found, index: %d.", node.err);
printf("Location found, index: %d.\n", node.err);
else
printf("Not found in this list.");
puts("Not found in this list.");
return node;
}
......
......@@ -2,48 +2,57 @@
#include<stdlib.h>
#include "llist.h"
void panic(){
puts("Not implemented yet!");
}
void menu(struct Node *head){
int choice;
printf("Welcome to the menu for creation of linked lists.\n");
printf("Displaying possible actions:\n");
printf("1. Add at End;\n2. Delete Node;\n3. Insert Node;\n4. Search for value;\n5. Print a node;\n6. Print full list;\n7. Delete list;\n8. Exit;\n");
printf("Please input the number of your desired action: ");
int menu(struct Node *head){
int choice, input;
puts("Welcome to the menu for creation of linked lists.");
puts("Displaying possible actions:");
puts("1. Add at End;\n2. Delete Node;\n3. Insert Node;\n4. Search for value;\n5. Print a node;\n6. Print full list;\n7. Delete list and exit;");
fputs("Please input the number of your desired action: ",stdout);
scanf("%d",&choice);
switch(choice)
{
case 1: //add at end
break;
case 1: //append
// break;
case 2: //delete node
// break;
case 3: //insert
panic();
break;
case 3: //insert node
break;
case 4: int val;
printf("You have selected to search for a value. Please input the value now: ");
scanf("%d",&val);
psearch(val,*head);
break;
case 5: int node;
printf("You have selected to print a node. Please input the node index now: ");
scanf("%d",&node);
print_node(node,*head);
case 4: //search
fputs("You have selected to search for a value. Please input the value now: ",stdout);
scanf("%d",&input);
psearch(head,input);
break;
case 6: printf("Printing full list.\n");
print_list(*head);
case 5: //print node
fputs("You have selected to print a node. Please input the node index now: ",stdout);
scanf("%d",&input);
print_node_at(head,input);
break;
case 7: //Delete list
case 6: //print list
puts("Printing full list.");
print_list(head);
break;
case 7: //delete list
puts("Deleting the list...");
delete_list(head);
return 1;
}
return 0;
}
int main1(){
int main(){
struct Node *start = NULL;
struct Node *start;
int arr[] = {10,20,30,40,50};
start = construct_list(arr, 5);
while(!menu(start))
;
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment