I'm new to data structures . I have been working for the past 72 hours to find an algorithm to insert a particular value into a singly linked list based on row and column index. I created the singly linked list based on the SPARSE MATRIX below.
I have attached the image of the linked list above. For an example, if i wanted to insert a value at row 0 and column 4 with the value of 8 . What is the most suitable algorithm to make this happen? Thanks in advance guys
An interesting point to consider.
First if you flatten your matrix, then you can notice that
Using this observation you can go through the list until the computed index of the cell you want to insert is smaller than the computed index of the current element.
If you know how to insert a node at a specific position in a linked list (which i recommend you try first if you dont) it should be easy to make the bridge between the two.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.