中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當前位置: 首頁 > news >正文

網(wǎng)站文件夾怎么做湖南長沙關鍵詞推廣電話

網(wǎng)站文件夾怎么做,湖南長沙關鍵詞推廣電話,全球速賣通中文官網(wǎng),做婚禮邀請函網(wǎng)站問題引入 上圖中,賦給b海象的weight會改變a海象的weight,但x的賦值又不會改變y的賦值 Bits 要解釋上圖的問題,我們應該從Java的底層入手 相同的二進制編碼,卻因為數(shù)據(jù)類型不同,輸出不同的值 變量的聲明 基本類型…
  • 問題引入
    在這里插入圖片描述

上圖中,賦給b海象的weight會改變a海象的weight,但x的賦值又不會改變y的賦值

Bits

要解釋上圖的問題,我們應該從Java的底層入手
在這里插入圖片描述
相同的二進制編碼,卻因為數(shù)據(jù)類型不同,輸出不同的值

變量的聲明

基本類型

Java does not write anything into the reserved box when a variable is declared. In other words, there are no default values. As a result, the Java compiler prevents you from using a variable until after the box has been filled with bits using the = operator. For this reason, I have avoided showing any bits in the boxes in the figure above.在這里插入圖片描述
在這里插入圖片描述

引用類型

When we declare a variable of any reference type (Walrus, Dog, Planet, array, etc.), Java allocates a box of 64 bits, no matter what type of object.
在這里插入圖片描述
96位大于64位,這似乎有些矛盾:
在Java中:the 64 bit box contains not the data about the walrus, but instead the address of the Walrus in memory.

Gloden rule

在這里插入圖片描述

在這里插入圖片描述

練習

在這里插入圖片描述
答案:B
解析:

  • 在調用方法(函數(shù))時,doStuff方法中的int x與main方法中的int x 實際上處于兩個不同的scope(調用方法時會new 一個scope,并將main方法中的x變量的位都傳遞給doStuff方法中的x變量,即值傳遞),所以x = x - 5實際上只作用于doStuff方法中的x,而不是main方法中的x。
  • 但對于引用類型來說,引用類型儲存的是引用的地址,所以在進行值傳遞時傳遞的是對象的地址,所以doStuff方法中的int x與main方法中的walrus實際上指向相同的一個對象,這使得doStuff中執(zhí)行的語句會作用于main方法中walrus指向的對象,所以反作用于main方法中的walrus

IntLists

在這里插入圖片描述
在這里插入圖片描述

使用遞歸求鏈表中元素的個數(shù)

/** Return the size of the list using... recursion! */
public int size() {if (rest == null) {return 1;}return 1 + this.rest.size();
}

Exercise: You might wonder why we don’t do something like if (this == null) return 0;. Why wouldn’t this work?

Answer: Think about what happens when you call size. You are calling it on an object, for example L.size(). If L were null, then you would get a NullPointer error!

不使用遞歸求元素個數(shù)

/** Return the size of the list using no recursion! */
public int iterativeSize() {IntList p = this;int totalSize = 0;while (p != null) {totalSize += 1;p = p.rest;}return totalSize;
}

求第n個元素

在這里插入圖片描述

SLList

接下來我們對IntList進行改進,使鏈表看上去不那么naked
在這里插入圖片描述
有了節(jié)點類,現(xiàn)在我們補充上鏈表類

public class SLList {public IntNode first;public SLList(int x) {first = new IntNode(x, null);}
}

對比SLList和IntList,我們發(fā)現(xiàn),在使用SLList時無需強調null

IntList L1 = new IntList(5, null);
SLList L2  = new SLList(5);

addFirst() and getFirst()

  /** Adds an item to the front of the list. */public void addFirst(int x) {first = new IntNode(x, first);}/** Retrieves the front item from the list. */public int getFirst() {return first.item;
}

private and nested class

public class SLList {public class IntNode {public int item;public IntNode next;public IntNode(int i, IntNode n) {item = i;next = n;}}private IntNode first;public SLList(int x) {first = new IntNode(x, null);}/** Adds an item to the front of the list. */public void addFirst(int x) {first = new IntNode(x,first);}/** Retrieves the front item from the list. */public int getFirst() {return first.item;}
}

addLast() and Size()

/** Adds an item to the end of the list. */
public void addLast(int x) {IntNode p = first;/* Advance p to the end of the list. */while (p.next != null) {p = p.next;}p.next = new IntNode(x, null);
}
/** Returns the size of the list starting at IntNode p. */
private static int size(IntNode p) {if (p.next == null) {return 1;}return 1 + size(p.next);
}

優(yōu)化低效的Size()方法

在改變鏈表的Size時直接記錄下,就可以不需要在Size()方法中遍歷鏈表了

public class SLList {... /* IntNode declaration omitted. */private IntNode first;private int size;public SLList(int x) {first = new IntNode(x, null);size = 1;}public void addFirst(int x) {first = new IntNode(x, first);size += 1;}public int size() {return size;}...
}

空鏈表( The Empty List)

創(chuàng)建空鏈表很簡單(對于SLList),但會導致addLast()方法報錯

public SLList() {first = null;size = 0;
}
public void addLast(int x) {size += 1;IntNode p = first;while (p.next != null) {p = p.next;}p.next = new IntNode(x, null);
}

p指向null,故p.next會出現(xiàn)空指針異常

addLast()改進(使用分支)
public void addLast(int x) {size += 1;if (first == null) {first = new IntNode(x, null);return;}IntNode p = first;while (p.next != null) {p = p.next;}p.next = new IntNode(x, null);
}
addLast()改進(更robust的做法)

對于存在很多特殊情況需要討論的數(shù)據(jù)結構,上面的方法就顯得十分低效。
故我們需要考慮將其改進為一個具有普適性的方法:將first改為sentinal.next
sentinal將會永遠存在于鏈表的上位

package lists.sslist;public class SLList {public class IntNode {public int item;public IntNode next;public IntNode(int i, IntNode n) {item = i;next = n;}}private IntNode sentinel;private int size;public SLList() {sentinel = new IntNode(63,null);size = 0;}public SLList(int x) {sentinel = new IntNode(63,null);sentinel.next = new IntNode(x, null);size = 1;}/** Adds an item to the front of the list. */public void addFirst(int x) {sentinel.next = new IntNode(x, sentinel.next);size += 1;}/** Retrieves the front item from the list. */public int getFirst() {return sentinel.next.item;}/** Returns the number of items in the list. */public int size() {return size;}/** Adds an item to the end of the list. */public void addLast(int x) {IntNode p = sentinel;/* Advance p to the end of the list. */while (p.next != null) {p = p.next;}p.next = new IntNode(x, null);}/** Crashes when you call addLast on an empty SLList. Fix it. */public static void main(String[] args) {SLList x = new SLList();x.addLast(5);}
}
http://www.risenshineclean.com/news/57699.html

相關文章:

  • 網(wǎng)站開發(fā)(七)數(shù)據(jù)庫的建表與連接云南疫情最新情況
  • 網(wǎng)站做nat映射需要哪些端口市場營銷策劃ppt
  • 如何做商業(yè)網(wǎng)站分析長春網(wǎng)站建設團隊
  • 網(wǎng)站流量少怎么辦鄭州百度推廣公司
  • wordpress 插件頁面seo關鍵詞排名點擊工具
  • 新浪推網(wǎng)站阿里大數(shù)據(jù)官網(wǎng)
  • 泉州網(wǎng)站建設公司首選網(wǎng)站綜合查詢工具
  • 個人適合做什么網(wǎng)站域名??烤W(wǎng)頁推廣大全
  • 英文 日文網(wǎng)站建設申請線上營銷的優(yōu)勢
  • 一級a做爰片在線看網(wǎng)站公司搜索seo
  • 襄陽營銷型網(wǎng)站愛站網(wǎng)絡挖掘詞
  • 深圳最新消息公布長沙seo服務
  • 做調查問卷賺錢網(wǎng)站有哪些培訓seo哪家學校好
  • 網(wǎng)站建設投訴去哪里投訴軟件推廣的渠道是哪里找的
  • 什么是網(wǎng)站域名?會計培訓班要多少錢一般要學多久
  • 電子商務網(wǎng)站建設與管理習題答案免費服務器
  • 免費網(wǎng)站推廣工具有哪些百度搜索排行榜前十名
  • 如何做網(wǎng)站的的關鍵詞網(wǎng)絡培訓學校
  • 免費做網(wǎng)站wxp114百度愛采購優(yōu)化軟件
  • 長春市疫情最新消息今天行動軌跡湖南網(wǎng)站seo營銷
  • 258做網(wǎng)站怎么樣網(wǎng)站排名優(yōu)化+o+m
  • 自己做優(yōu)惠劵網(wǎng)站賺錢嗎網(wǎng)站seo是干什么的
  • 響應式網(wǎng)站新聞部分怎么做aso優(yōu)化軟件
  • 順徳網(wǎng)站建設公司有哪些搜索關鍵詞排名優(yōu)化軟件
  • 臨沂品牌網(wǎng)站推廣人民日報今日新聞
  • ui設計技術培訓學校十堰seo優(yōu)化
  • 房產(chǎn)這么做網(wǎng)站才多點擊量2023新聞熱點摘抄
  • 佳木斯建設工程交易中心網(wǎng)站自助建站
  • 建筑培訓網(wǎng)站網(wǎng)絡廣告策劃的內容
  • 青縣做網(wǎng)站價格好看的網(wǎng)站ui