GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Merge pull request #1054 from shellhub/feature · feiteng/Java@6e8aaaa

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • DataStructures/Lists
    • SinglyLinkedList.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎DataStructures/Lists/SinglyLinkedList.java‎

Copy file name to clipboardExpand all lines: DataStructures/Lists/SinglyLinkedList.java
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,25 @@ public void deleteNth(int position) {
106106
}
107107
}
108108

109+
/**
110+
* clear all nodes in list
111+
*/
112+
public void clear() {
113+
if (size == 0) {
114+
return;
115+
}
116+
Node prev = head.next;
117+
Node cur = prev.next;
118+
while (cur != null) {
119+
prev = null; // clear to let GC do its work
120+
prev = cur;
121+
cur = cur.next;
122+
}
123+
prev = null;
124+
head.next = null;
125+
size = 0;
126+
}
127+
109128
/**
110129
* Checks if the list is empty
111130
*

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.