Constructing the stiffness matrix of a finite element and assembling the stiffness matrix of a model are two different things. What are you trying to do here exactly? What type of problem are you solving and what type of elements are you using?
Procedure for assembling stiffness matrices generally does not vary with systems(Linear or Nonlinear). It depends only on the connectivity of the nodes. Best practice is to make a connectivity matrix and use it for assembling.
What you are saying is true but in the case of nonlinear analysis the stiffness matrix is assembled several times while in the linear case you perform this only once.This means that your stiffness matrix during the nonlinear procedure will change and it will be numerically controlled by the update of your constitutive matrix according to the level of plastification at each load increment. This is the reason why I am asking you about the nonlinear solution procedure that you are implementing through your algorithm.What is the numerical result that you are getting in order for you to conclude that you have a problem? You just say that the stiffness matrix cannot be assembled. This doesn't help in determining what is the actual problem.If in your case the algorithm stops during the stiffness assembly procedure then one can easily conclude that your algorithmic implementation is wrong.