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){ ...@@ -10,7 +10,7 @@ void print_node_at(NODE *head, int pos){
for (int i = 0; i<pos; i++){ for (int i = 0; i<pos; i++){
currentNode = currentNode->next; 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){ void print_node(NODE *head){
...@@ -31,14 +31,13 @@ void print_list(NODE *head){ ...@@ -31,14 +31,13 @@ void print_list(NODE *head){
} }
} }
NODE_ERR psearch(NODE *head, datatype data){ 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); NODE_ERR node = search(head, data);
if(node.node != NULL) if(node.node != NULL)
printf("Location found, index: %d.", node.err); printf("Location found, index: %d.\n", node.err);
else else
printf("Not found in this list."); puts("Not found in this list.");
return node; return node;
} }
......
...@@ -2,48 +2,57 @@ ...@@ -2,48 +2,57 @@
#include<stdlib.h> #include<stdlib.h>
#include "llist.h" #include "llist.h"
void panic(){
puts("Not implemented yet!");
}
void menu(struct Node *head){ int menu(struct Node *head){
int choice; int choice, input;
printf("Welcome to the menu for creation of linked lists.\n"); puts("Welcome to the menu for creation of linked lists.");
printf("Displaying possible actions:\n"); puts("Displaying possible actions:");
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"); 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;");
printf("Please input the number of your desired action: "); fputs("Please input the number of your desired action: ",stdout);
scanf("%d",&choice); scanf("%d",&choice);
switch(choice) switch(choice)
{ {
case 1: //add at end case 1: //append
break; // break;
case 2: //delete node case 2: //delete node
// break;
case 3: //insert
panic();
break; break;
case 3: //insert node case 4: //search
break; fputs("You have selected to search for a value. Please input the value now: ",stdout);
case 4: int val; scanf("%d",&input);
printf("You have selected to search for a value. Please input the value now: "); psearch(head,input);
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);
break; break;
case 6: printf("Printing full list.\n"); case 5: //print node
print_list(*head); fputs("You have selected to print a node. Please input the node index now: ",stdout);
scanf("%d",&input);
print_node_at(head,input);
break; break;
case 7: //Delete list case 6: //print list
puts("Printing full list.");
print_list(head);
break; 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}; int arr[] = {10,20,30,40,50};
start = construct_list(arr, 5);
while(!menu(start))
;
return 0; 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