GromHellscream
V2EX  ›  问与答

这个 func swap 函数( Swift 实现)该如何理解?

  •  
  •   GromHellscream · Apr 20, 2019 · 1101 views
    This topic created in 2578 days ago, the information mentioned may be changed or developed.
    fileprivate func reverse<T>(_ chars: inout [T], _ start: Int, _ end: Int) {
      var start = start, end = end
    
      while start < end {
        swap(&chars, start, end)
        start += 1
        end -= 1
      }
    }
    
    fileprivate func swap<T>(_ chars: inout [T], _ p: Int, _ q: Int) {
      (chars[p], chars[q]) = (chars[q], chars[p]) //请问,这一行该怎么理解?
    }
    
    1 replies    2019-04-20 21:41:31 +08:00
    GromHellscream
        1
    GromHellscream  
    OP
       Apr 20, 2019
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3322 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 00:31 · PVG 08:31 · LAX 17:31 · JFK 20:31
    ♥ Do have faith in what you're doing.