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

separate search and psearch

moved the portions of search() that call printf to psearch(), so that it can be
used silently
parent 118be38a
......@@ -30,20 +30,30 @@ void print_list(NODE *head){
}
NODE* search(NODE *head, int pos){
printf("Searching list for: %d", pos);
NODE *currentNode;
currentNode = head;
NODE_ERR psearch(NODE *head, datatype data){
printf("Searching list for: %d", data);
NODE_ERR node = search(head, data);
if(node.node != NULL)
printf("Location found, index: %d.", node.err);
else
printf("Not found in this list.");
return node;
}
while (currentNode != NULL){
if(currentNode->data == pos){
printf("Location found, index: %d.", currentNode);
return currentNode;
NODE_ERR search(NODE *head, datatype data){
NODE_ERR currentNode;
curr.node = head;
int i;
for(i=0;curr.node != NULL;i++){
if(curr.node->data == data){
curr.err=i;
return curr;
}
currentNode=currentNode->next;
curr.node=curr.node->next;
}
printf("Not found in this list.");
curr.node = NULL;
curr.err = -1;
return curr;
}
NODE *construct(datatype data, NODE *next){
......
......@@ -14,7 +14,8 @@ typedef struct Node_Err
void print_node(NODE *head, int pos);
void print_list(NODE *head);
NODE *search(NODE *head, datatype data);
NODE_ERR psearch(NODE *head, datatype data);
NODE_ERR search(NODE *head, datatype data);
NODE *construct(datatype data, NODE *next);
NODE *traverse(NODE *head, int pos);
int delete_node_after(NODE *head);
......
......@@ -21,7 +21,7 @@ void menu(struct Node *head){
case 4: int val;
printf("You have selected to search for a value. Please input the value now: ");
scanf("%d",&val);
search(val,*head);
psearch(val,*head);
break;
case 5: int node;
printf("You have selected to print a node. Please input the node index now: ");
......
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