This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class App { | |
public static void main(String[] args) { | |
int[] array = {5,9,1,8,2,7,3,6,4}; | |
System.out.println("original " + array); | |
bubbleSort(array); | |
System.out.println("sorted " + array); | |
} | |
private static void bubbleSort(int[] array) { | |
boolean swapped; | |
int n = array.length; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
/* | |
1108. Defanging an IP Address | |
Given a valid (IPv4) IP address, return a defanged version of that IP address. | |
A defanged IP address replaces every period "." with "[.]". | |
Example 1: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Contacts | |
func createContact()->CNMutableContact{ | |
let contact = CNMutableContact() | |
contact.namePrefix = "John" | |
contact.nameSuffix = "Applesee" | |
contact.organizationName = "Apple" | |
contact.jobTitle = "Software Engineer" | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func quickSort<T:Comparable>(_ list:[T])->[T]{ | |
if list.count == 0 { | |
return [] | |
} | |
let pivot = list[list.count/2] | |
let equal = list.filter{ $0 == pivot } | |
let less = list.filter{ $0 < pivot } | |
let greater = list.filter{ $0 > pivot } | |
return quickSort(less) + equal + quickSort(greater) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let sampleTextField = UITextField(frame: CGRectMake(20, 100, 300, 40)) | |
sampleTextField.placeholder = "Enter text here" | |
sampleTextField.font = UIFont.systemFontOfSize(15) | |
sampleTextField.borderStyle = UITextBorderStyle.RoundedRect | |
sampleTextField.autocorrectionType = UITextAutocorrectionType.No | |
sampleTextField.keyboardType = UIKeyboardType.Default | |
sampleTextField.returnKeyType = UIReturnKeyType.Done | |
sampleTextField.clearButtonMode = UITextFieldViewMode.WhileEditing; | |
sampleTextField.contentVerticalAlignment = UIControlContentVerticalAlignment.Center | |
sampleTextField.delegate = self |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lazy var v1:UIView = { | |
let v = UIView() | |
v.backgroundColor = .blueColor() | |
return v | |
}() | |
lazy var v2:UIView = { | |
let v = UIView() | |
v.backgroundColor = .blueColor() | |
return v |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let sentence = "Hello, My name is Bob" | |
let result = sentence.characters.reversed().map { String($0) }.joined(separator:"") | |
print(result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func quicksort<T:Comparable>(list:[T])->[T]{ | |
if list.isEmpty { | |
return list | |
} | |
let pivot = list[list.count/2] | |
let equal = list.filter{ $0 == pivot } | |
let less = list.filter{ $0 < pivot } | |
let greater = list.filter{ $0 > pivot } | |
return quicksort(less) + equal + quicksort(greater) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// HTTP.swift | |
// TableTest2 | |
// | |
// Created by Gazolla on 22/05/16. | |
// Copyright © 2016 Gazolla. All rights reserved. | |
// | |
import Foundation | |
import UIKit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
char inData[20]; // Allocate some space for the string | |
char inChar=-1; // Where to store the character read | |
byte index = 0; // Index into array; where to store the character | |
void setup() { | |
Serial.begin(9600); | |
Serial.write("Power On"); | |
} | |
char Comp(char* This) { |
NewerOlder