LinkedList Part

前端 未结 4 1324
小鲜肉
小鲜肉 2021-01-28 12:44

I think I might have done something right, headByRating and headByName both refer to the same address.

I have been drawing diagras working all day trying new things etc,

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-28 13:02

    It looks like you have several problems here:

    1. It will always skip the while statement since temp->nextByName will always be NULL since temp points to current which is a new object.
    2. You're creating a node object from winery twice
    3. You're assigning the item member to winery after you sent it in the constructor
    4. You're making the nextByName and nextByRating members point to itself

    I'd recommend removing everything from this method and writing high-level pseudo code in its place. Then create a smaller method for each line of pseudo code. Smaller logical methods called inside insert will help it make sense.

提交回复
热议问题