Commit 81a41a5c authored by Liam E. Roeth's avatar Liam E. Roeth

Merge branch 'master' of https://git.cs.hofstra.edu/h702747900/linked_list2

Conflicts:
	llist.c
	main.c
parents 07654e18 d0d22181
...@@ -129,6 +129,28 @@ NODE_INT search_before(NODE *head, datatype data, unsigned before){ ...@@ -129,6 +129,28 @@ NODE_INT search_before(NODE *head, datatype data, unsigned before){
return out; return out;
} }
NODE_INT traverseBefore(NODE *head, int pos, int offset){
int newPos = pos-offset;
NODE_INT returnCode = traverse(head, newPos);
switch(returnCode.num){
case 0: printf("Case 0-> here is the data: %d\n", returnCode.node->data);
break;
case 1: printf("Case 1-> here is the data: %d\n",returnCode.node->data);
break;
case 2: printf("Not in the list; returning final data point: %d\n",returnCode.node->data);
break;
}
}
int delete_node_at(NODE *head, int pos){
NODE_INT nodeToDelete = traverse(head, pos);
NODE_INT priorNode = traverse(head, pos-1);
priorNode.node->next = nodeToDelete.node->next;
//NODE *nextNode = nodeToDelete.node->next;
free(nodeToDelete.node);
return 0;
}
int delete_node_after(NODE *head){ int delete_node_after(NODE *head){
//return: //return:
// 0 : normal // 0 : normal
......
...@@ -20,10 +20,10 @@ NODE_INT search(NODE *head, datatype data); ...@@ -20,10 +20,10 @@ NODE_INT search(NODE *head, datatype data);
NODE_INT search_before(NODE *head, datatype data, unsigned before); NODE_INT search_before(NODE *head, datatype data, unsigned before);
NODE *construct(datatype data, NODE *next); NODE *construct(datatype data, NODE *next);
NODE_INT traverse(NODE *head, int pos); NODE_INT traverse(NODE *head, int pos);
//NODE_INT traverse_before(NODE *head, int pos, int before); NODE_INT traverseBefore(NODE *head, int pos, int offset);
int delete_node_after(NODE *head); int delete_node_after(NODE *head);
void delete_list(NODE *head); void delete_list(NODE *head);
//int delete_node_at(NODE *head, int pos); int delete_node_at(NODE *head, int pos);
//int delete_node(NODE *head, datatype data); //int delete_node(NODE *head, datatype data);
NODE *construct_list(datatype list[], int size); NODE *construct_list(datatype list[], int size);
int add_to_end(NODE *head, datatype new_data); int add_to_end(NODE *head, datatype new_data);
......
...@@ -7,21 +7,23 @@ void panic(){ ...@@ -7,21 +7,23 @@ void panic(){
} }
int menu(struct Node *head){ int menu(struct Node *head){
int choice, input, index, value; int input, index, value;
puts("\nWelcome to the menu for creation of linked lists."); puts("\nWelcome to the menu for creation of linked lists.");
puts("Displaying possible actions:"); 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;"); 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;\n8. Print node prior to selected.\n");
fputs("Please input the number of your desired action: ",stdout); fputs("Please input the number of your desired action: ",stdout);
scanf("%d",&choice); scanf("%d",&input);
switch(choice) switch(input)
{ {
case 1: //append case 1: //append
fputs("You have decided to insert a value at the end. Input the desired value now: ",stdout); fputs("You have decided to insert a value at the end. Input the desired value now: ",stdout);
scanf("%d",&value); scanf("%d",&value);
add_to_end(head, value); add_to_end(head, value);
break; break;
case 2: //delete node case 2: //delete node at
panic(); fputs("You have decided to delete a node. Input it: ",stdout);
scanf("%d",&index);
delete_node_at(head, index);
break; break;
case 3: //insert case 3: //insert
fputs("You have decided to insert a value at a specific point. Input the node index now: ",stdout); fputs("You have decided to insert a value at a specific point. Input the node index now: ",stdout);
...@@ -32,13 +34,13 @@ int menu(struct Node *head){ ...@@ -32,13 +34,13 @@ int menu(struct Node *head){
break; break;
case 4: //search case 4: //search
fputs("You have selected to search for a value. Please input the value now: ",stdout); fputs("You have selected to search for a value. Please input the value now: ",stdout);
scanf("%d",&input); scanf("%d",&value);
psearch(head,input); psearch(head,value);
break; break;
case 5: //print node case 5: //print node
fputs("You have selected to print a node. Please input the node index now: ",stdout); fputs("You have selected to print a node. Please input the node index now: ",stdout);
scanf("%d",&input); scanf("%d",&index);
print_node_at(head,input); print_node_at(head,index);
break; break;
case 6: //print list case 6: //print list
puts("Printing full list."); puts("Printing full list.");
...@@ -48,6 +50,14 @@ int menu(struct Node *head){ ...@@ -48,6 +50,14 @@ int menu(struct Node *head){
puts("Deleting the list..."); puts("Deleting the list...");
delete_list(head); delete_list(head);
return 1; return 1;
case 8: //return data two areas before
puts("Returning data at offset");
fputs("Please input the node index now: ",stdout);
scanf("%d",&index);
fputs("Please input the offset prior now: ",stdout);
scanf("%d",&value);
traverseBefore(head,index,value);
break;
} }
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