The goal of the program is to make a sparse matrix using circularly linked lists. basically its a matix what only has values at the locations entered, and the rest of the lactions are not defined. the question i have is the logic for the code. how would i go about traversing and adding elements to the list with out defining the elements i dont want to define, as well as linking it to the other horizontal/vertical components

First think about what a matrix is: an ordered series of rows. This may seem obvious, but it makes it simple to take those rows and make one very long row (you just have to remember that every 'x' values is a new row). This structure could easily be converted to a linked list. To allow yourself to add elements without keeping values in between, simply keep a distance value in a node that defines how much "null space" is between this value and the next actual value. Just be sure to appropriately update this sturcture when adding/removing values from the matrix.

Hope this helps!

i think you should have to follow the algorithm like:

start
Enter the row and column matrix
Read the value of m and n
Set for loop i< row as i=1 and another loop i < col as j=1
Read value of x
      Next j and i
If we choose insert then check if (sparse == Null ) then sparse =p
      Else check while (q-> next != Null ) then q = q-> next; q-> next =p
If we choose display than for i=1 to r then check p=p->next
stop

i hope this might be correct

commented: Explains solution without spoon-feeding +14

The idea from jalpesh_007 is fine, but the idea from dmanw100 is better. The reason is that the idea of dmanw100 requires less space and time to traversal through the list. However, it also requires more caution in insertion/removal. For now, you may follow jalpesh_007 idea. For more advance (in the future), you could try dmanw100 idea.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.