int listSize = 0;
CalendarLinkedList firstList = new CalendarLinkedList();
CalendarLinkedList currentList = firstList;
for(int a = 0; a < listSize; listSize ++)
{
currentList = firstList.next;
}
CalendarLinkedList newList = new CalendarLinkedList(todayDate, listSize + 1);
newList.setPrev(currentList);
currentList.setNext(newList);
currentList = newList;
This is one part of my linked list, will the nodes be alligned properly? Because it seems like newList is not going next to currentList properly.
listSize is like a counter.
I thought if I write my codes like this, a new list will come next to firstList, then the current will become the new List. Am I wrong?
Assuming that the variable firstList
points to the head of the list you want to add to, you probably want something like this:
int listSize = 0;
CalendarLinkedList currentList = firstList;
while (currentList.next != null)
{
currentList = currentList.next;
listSize++;
}
CalendarLinkedList newList = new CalendarLinkedList(todayDate, listSize + 1);
newList.setPrev(currentList);
currentList.setNext(newList);
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.