Skip to main content
surrounding more code with backticks
Source Link
Snowbody
  • 8.7k
  • 25
  • 50

iter is set to the head of the linked list, and if the linked list doesn't yet exist, you reply that the item is "not found\n""not found\n". I would change this to "Linked list is empty.\n""Linked list is empty.\n"

This doesn't seem to work in the sense that it does not actually delete the element. If you want this item deleted -- which I'm assuming you do, given the name of the function -- then you should add this line: head = head->next; (You'll need to pass the head parameter "by reference" to make sure that this change will propagate outside the code of the delete_item function. Normally, if the parameter being passed wasn't a pointer, this would be done by passing the pointer. head head is a node*node*, however, and I have forgotten how to pass a pointer by reference... I think it would either be node*& head or node** head ... sorry, but you'll have to figure that one out! :) ) Alternatively, you could have delete_item return a node *, and at the end of the function, you could return the first non-matching entry, and this would be called by head=delete_item(head, x)head=delete_item(head, x). It's probably slightly frowned upon to do it that way, but it would be an easy way out.

At any rate, once you get that accomplished, it will delete the current head, and the new head will be the second element, if one exists... else it will be set to NULLNULL.

One problem I see is that you have to decide if you want to delete duplicate entries. For example, if 77 appears twice in the linked list, do you want to delete both 7s7s, or just one? If you want to delete both, you need to traverse the entire linked list by removing the return statements in the whilewhile loop and the initial check of the head node. This will create a problem as the program proceeds on to the final, "not found" statement, but that can be solved with an ifif statement:

entryfoundentryfound would have to be declared to be 00, and set to 11 if a match was found in the whilewhile loop. Alternatively, you could do entryfound++entryfound++ in the event of a match and change this last line:

iter is set to the head of the linked list, and if the linked list doesn't yet exist, you reply that the item is "not found\n". I would change this to "Linked list is empty.\n"

This doesn't seem to work in the sense that it does not actually delete the element. If you want this item deleted -- which I'm assuming you do, given the name of the function -- then you should add this line: head = head->next; (You'll need to pass the head parameter "by reference" to make sure that this change will propagate outside the code of the delete_item function. Normally, if the parameter being passed wasn't a pointer, this would be done by passing the pointer. head is a node*, however, and I have forgotten how to pass a pointer by reference... I think it would either be node*& head or node** head ... sorry, but you'll have to figure that one out! :) ) Alternatively, you could have delete_item return a node *, and at the end of the function, you could return the first non-matching entry, and this would be called by head=delete_item(head, x). It's probably slightly frowned upon to do it that way, but it would be an easy way out.

At any rate, once you get that accomplished, it will delete the current head, and the new head will be the second element, if one exists... else it will be set to NULL.

One problem I see is that you have to decide if you want to delete duplicate entries. For example, if 7 appears twice in the linked list, do you want to delete both 7s, or just one? If you want to delete both, you need to traverse the entire linked list by removing the return statements in the while loop and the initial check of the head node. This will create a problem as the program proceeds on to the final, "not found" statement, but that can be solved with an if statement:

entryfound would have to be declared to be 0, and set to 1 if a match was found in the while loop. Alternatively, you could do entryfound++ in the event of a match and change this last line:

iter is set to the head of the linked list, and if the linked list doesn't yet exist, you reply that the item is "not found\n". I would change this to "Linked list is empty.\n"

This doesn't seem to work in the sense that it does not actually delete the element. If you want this item deleted -- which I'm assuming you do, given the name of the function -- then you should add this line: head = head->next; (You'll need to pass the head parameter "by reference" to make sure that this change will propagate outside the code of the delete_item function. Normally, if the parameter being passed wasn't a pointer, this would be done by passing the pointer. head is a node*, however, and I have forgotten how to pass a pointer by reference... I think it would either be node*& head or node** head ... sorry, but you'll have to figure that one out! :) ) Alternatively, you could have delete_item return a node *, and at the end of the function, you could return the first non-matching entry, and this would be called by head=delete_item(head, x). It's probably slightly frowned upon to do it that way, but it would be an easy way out.

At any rate, once you get that accomplished, it will delete the current head, and the new head will be the second element, if one exists... else it will be set to NULL.

One problem I see is that you have to decide if you want to delete duplicate entries. For example, if 7 appears twice in the linked list, do you want to delete both 7s, or just one? If you want to delete both, you need to traverse the entire linked list by removing the return statements in the while loop and the initial check of the head node. This will create a problem as the program proceeds on to the final, "not found" statement, but that can be solved with an if statement:

entryfound would have to be declared to be 0, and set to 1 if a match was found in the while loop. Alternatively, you could do entryfound++ in the event of a match and change this last line:

added 304 characters in body; deleted 2 characters in body
Source Link
Michael
  • 323
  • 4
  • 9

This doesn't seem to work in the sense that it does not actually delete the element. If you want this item deleted -- which I'm assuming you do, given the name of the function -- then you should add this line: head = head->next; (You'll need to pass the head parameter "by reference" to make sure that this change will propagate outside the code of the delete_item function. Normally, if the parameter being passed wasn't a pointer, this would be done by passing the pointer. head is a node*, however, and I have forgotten how to pass a pointer by reference... I think it would either be node*& head or node** head ... sorry, but you'll have to figure that one out! :) ) At any rate Alternatively, once you get that accomplishedcould have delete_item return a node *, it will deleteand at the current headend of the function, andyou could return the new head willfirst non-matching entry, and this would be the second elementcalled by head=delete_item(head, if one exists..x). else It's probably slightly frowned upon to do it willthat way, but it would be set to NULLan easy way out.

At any rate, once you get that accomplished, it will delete the current head, and the new head will be the second element, if one exists... else it will be set to NULL.

if (entryfound) { printf("%i matches found and deleted.\n", entryfound); }
  else { printf("No matches found.\n"); }

This doesn't seem to work in the sense that it does not actually delete the element. If you want this item deleted -- which I'm assuming you do, given the name of the function -- then you should add this line: head = head->next; (You'll need to pass the head parameter "by reference" to make sure that this change will propagate outside the code of the delete_item function. Normally, if the parameter being passed wasn't a pointer, this would be done by passing the pointer. head is a node*, however, and I have forgotten how to pass a pointer by reference... I think it would either be node*& head or node** head ... sorry, but you'll have to figure that one out! :) ) At any rate, once you get that accomplished, it will delete the current head, and the new head will be the second element, if one exists... else it will be set to NULL.

if (entryfound) {printf("%i matches found and deleted.\n");}
  else { printf("No matches found.\n"); }

This doesn't seem to work in the sense that it does not actually delete the element. If you want this item deleted -- which I'm assuming you do, given the name of the function -- then you should add this line: head = head->next; (You'll need to pass the head parameter "by reference" to make sure that this change will propagate outside the code of the delete_item function. Normally, if the parameter being passed wasn't a pointer, this would be done by passing the pointer. head is a node*, however, and I have forgotten how to pass a pointer by reference... I think it would either be node*& head or node** head ... sorry, but you'll have to figure that one out! :) ) Alternatively, you could have delete_item return a node *, and at the end of the function, you could return the first non-matching entry, and this would be called by head=delete_item(head, x). It's probably slightly frowned upon to do it that way, but it would be an easy way out.

At any rate, once you get that accomplished, it will delete the current head, and the new head will be the second element, if one exists... else it will be set to NULL.

if (entryfound) { printf("%i matches found and deleted.\n", entryfound); }
  else { printf("No matches found.\n"); }
added 31 characters in body; edited body
Source Link
Michael
  • 323
  • 4
  • 9

This doesn't seem to work in the sense that it does not actually delete the element. If you want this item deleted -- which I'm assuming you do, given the name of the function -- then you should add this line: head = head->next; (You'll need to pass the head parameter "by reference" to make sure that this change will propagate outside the code of the delete_item function. Normally, if the parameter being passed wasn't a pointer, this would be done by passing the pointer. head is a node*, however, and I have forgotten how to pass a pointer by reference... I think it would either be node*& head or node** head ... sorry, but you'll have to figure that one out! :) ) At any rate, once you get that accomplished, it will delete the current head, and the new head will be the second element, if one exists... else it will be set to NULL.

One problem I see is that you have to decide if you want to delete duplicate entries. For example, if 7 appears twice in the linked list, do you want to delete both 7s, or just one? If you want to delete both, you need to traverse the entire linked list by removing the return statements in the while loop and the initial check of the head node. This will create a problem as the program proceesdproceeds on to the final, "not found" statement, but that can be solved with an if statement:

This doesn't seem to work in the sense that it does not actually delete the element. If you want this item deleted -- which I'm assuming you do, given the name of the function -- then you should add this line: head = head->next; (You'll need to pass the head parameter "by reference" to make sure that this change will propagate outside the code of the delete_item function. Normally, if the parameter being passed wasn't a pointer, this would be done by passing the pointer. head is a node*, however, and I have forgotten how to pass a pointer by reference... I think it would either be node*& head or node** head ... sorry, but you'll have to figure that one out! :) ) At any rate, once you get that accomplished, it will delete the current head, and the new head will be the second element, if one exists.

One problem I see is that you have to decide if you want to delete duplicate entries. For example, if 7 appears twice in the linked list, do you want to delete both 7s, or just one? If you want to delete both, you need to traverse the entire linked list by removing the return statements in the while loop and the initial check of the head node. This will create a problem as the program proceesd on to the final, "not found" statement, but that can be solved with an if statement:

This doesn't seem to work in the sense that it does not actually delete the element. If you want this item deleted -- which I'm assuming you do, given the name of the function -- then you should add this line: head = head->next; (You'll need to pass the head parameter "by reference" to make sure that this change will propagate outside the code of the delete_item function. Normally, if the parameter being passed wasn't a pointer, this would be done by passing the pointer. head is a node*, however, and I have forgotten how to pass a pointer by reference... I think it would either be node*& head or node** head ... sorry, but you'll have to figure that one out! :) ) At any rate, once you get that accomplished, it will delete the current head, and the new head will be the second element, if one exists... else it will be set to NULL.

One problem I see is that you have to decide if you want to delete duplicate entries. For example, if 7 appears twice in the linked list, do you want to delete both 7s, or just one? If you want to delete both, you need to traverse the entire linked list by removing the return statements in the while loop and the initial check of the head node. This will create a problem as the program proceeds on to the final, "not found" statement, but that can be solved with an if statement:

deleted 104 characters in body; added 22 characters in body
Source Link
Michael
  • 323
  • 4
  • 9
Loading
added 2847 characters in body; added 284 characters in body
Source Link
Michael
  • 323
  • 4
  • 9
Loading
added 12 characters in body
Source Link
Michael
  • 323
  • 4
  • 9
Loading
added 54 characters in body; deleted 1 characters in body
Source Link
Michael
  • 323
  • 4
  • 9
Loading
added 134 characters in body; added 94 characters in body
Source Link
Michael
  • 323
  • 4
  • 9
Loading
added 84 characters in body; added 160 characters in body
Source Link
Michael
  • 323
  • 4
  • 9
Loading
Source Link
Michael
  • 323
  • 4
  • 9
Loading