4--逆単独リンクリストリンクリストの問題

タイトル

逆方向リンクリストの機能を実装します


請求

鎖長がN、Oの時間複雑さの要件(N)、追加のスペース要件の複雑さをO(1)である場合。


ソース

public class Node{
	public int value;
	public Node next;
	public Node(int data){
		this.value=data;
	} 
}

public Node reverseList(Node head){
	Node pre=null;
	Node next=null;
	while(head!=null){
		next=head.next;
		head.next=pre;
		pre=head;
		head=next;
	}
	return pre;
	
}

 

公開された43元の記事 ウォン称賛21 ビュー4919

おすすめ

転載: blog.csdn.net/flying_1314/article/details/103837486