List - function flow diagram

Thread Starter

Gajyamadake

Joined Oct 9, 2019
313
I am trying to make flow diagram for single linked list in c program I have made my best attempt to understand logic below is rough explanation of list

1578656266048.png

Its output should be 2 4 8 I do not understand how to delete second node. When it deletes output should be 2 8 ?

Thank you for any kind of help
 

Attachments

KeithWalker

Joined Jul 10, 2017
880
We need a definition of what this process is supposed to do before we can comment on whether the flow chart is correct.
Regards,
Keith
 

JohnInTX

Joined Jun 26, 2012
4,051

Thread Starter

Gajyamadake

Joined Oct 9, 2019
313
We need a definition of what this process is supposed to do before we can comment on whether the flow chart is correct.
I have list that contain three nodes and I want to delete the second node. My flow diagram showed how to create a list. Now I want to show operation to delete second node in flow diagram. But i don't know how to do it

There is lots of good info for the cost of a search. Here's one that answers your question. You should have the operations worked out on paper before trying to flow chart the procedure.
I have read but i find it very difficult to understand So I thought that it should be as simple as it can be, So I have only three nodes in my list. And I'm trying to understand how any node can be deleted

I am reading more pages that have good information and try to make a good effort to understand delete operation
 

JohnInTX

Joined Jun 26, 2012
4,051
I have read but i find it very difficult to understand So I thought that it should be as simple as it can be, So I have only three nodes in my list. And I'm trying to understand how any node can be deleted
The image from https://www.cs.cmu.edu/~adamchik/15-121/lectures/Linked Lists/linked lists.html shows you how to delete a node. If you know how to add a node, how to delete it should be pretty obvious:
  1. Traverse the list keeping a copy of two pointers, prev(previous) and cur(current). Move both as you go from node to node.
  2. When you reach the node to delete, the pointers will be as shown in the picture (green arrows).
  3. Just make prev->next = cur->next to bypass the node pointed to by cur. (purple arrow) That makes prev->next point to node P.
  4. Release the memory used by node A by calling free(cur).

1578681608968.png
 
Last edited:

ApacheKid

Joined Jan 12, 2015
157
Understand, there are four cases to consider when removing a node from a list, be it doubly or singly linked, these are:

1. The list contains only one node.
2. The node is the head.
3. The node is the tail.
4. The node is not the head or the tail.

Node deletion algorithms thus begin by identifying which of these is the case, the code for each case is then rather simple.
 

ApacheKid

Joined Jan 12, 2015
157
Incidentally even something as apparently simple as removing a node from a list should be approached with caution, consider these kinds of things:

  • Might the node removal operation be interrupted partway and the list possibly accessed by an interrupt handler?
  • How do we know the node pointer actually does point to a node on this list?
  • What if we previously removed this same node already?

etc etc etc...
 
Top