Rahul Jain
BAN USER// Swift
// Creation of linked list
class Node
{
var value:Int // Contains value in node
var nextNode:Node? // Contains reference of next node
init(withValue value:Int)
{
self.value = value
}
}
protocol DataStructure
{
func add(value:Int)
func search(value:Int) -> Node?
func update(value:Int)
func remove(value:Int)
func display()
}
class LinkedList : DataStructure
{
var firstNode:Node?
init() {
}
private func createNode(withValue value:Int)-> Node
{
return Node(withValue: value)
}
private func getLastNode()->Node
{
var currentNode:Node = firstNode!
while currentNode.nextNode != nil {
currentNode = currentNode.nextNode!
}
return currentNode
}
func add(value:Int)
{
if firstNode == nil
{
firstNode = createNode(withValue: value)
}
let lastNode:Node = getLastNode()
lastNode.nextNode = Node(withValue: value)
}
func search(value:Int) -> Node?
{
var currentNode:Node = firstNode!
while currentNode.nextNode != nil {
if currentNode.value == value
{
return currentNode
}
currentNode = currentNode.nextNode!
}
return nil
}
func update(value:Int)
{
let node = search(value: value)
node?.value = value
}
func remove(value:Int)
{
var node = search(value: value)
let prevNode = search(value: value)
let afterNode = node?.nextNode
prevNode?.nextNode = afterNode
node = nil
}
func display()
{
var currentNode:Node = firstNode!
while currentNode.nextNode != nil {
currentNode = currentNode.nextNode!
print("node value \(currentNode.value)")
}
}
func maxOccurancesItems()->(Int, Int)
{
var currentNode:Node = firstNode!
var dict:Dictionary<Int,Int> = Dictionary<Int, Int>();
while currentNode.nextNode != nil {
currentNode = currentNode.nextNode!
var count:Int = -1
if dict[currentNode.value] != nil
{
count = dict[currentNode.value]!
}
else
{
count = 0
}
dict[currentNode.value] = count + 1
}
var maxOccuraces = 0
var maxKey :Int = 0
for key in dict.keys
{
if dict[key]! > maxOccuraces
{
maxKey = key
maxOccuraces = dict[key]!
}
}
return (maxKey,maxOccuraces)
}
}
let linkedList:LinkedList = LinkedList()
linkedList.add(value:4)
linkedList.add(value: 5)
linkedList.add(value: 1)
linkedList.add(value: 3)
linkedList.add(value: 5)
linkedList.add(value: 3)
linkedList.display()
// Find max frequency of occurances in linked list
let maxOccur = linkedList.maxOccurancesItems()
print(" Element \(maxOccur.0) and occurance \(maxOccur.1)")
RepConnieLavender, Animator at Altera
My name is ConnieLavender . I am working as a Broker associate . I love field work and visiting different places to ...
RepAtiDavis, Analyst at 8x8
I am a skilled construction worker with 3+ years of experience erecting structures according to blueprints and safely utilizing power ...
RepShayneRies, Android Engineer at ASAPInfosystemsPvtLtd
I am Shayne , working as a Playwright at Woilds , where I write scripts for theatrical productions. Works with more experienced ...
RepEllenaSimon, Animator at ABC TECH SUPPORT
Hello I am an event planner and I have been working in this field for almost 5 years. For a ...
Repdalecronin028, Animator at Pinterest
Hello, I am Dale. I am a Tourist guide who welcomes tourists . Tourist Guides act as ambassadors of the country ...
RepNirvedPerez, abc at 8x8
To make sure a thorough investigation is done if discrepancies occur. Execute the Brand Customer Service standards to meet or ...
RepGizzyKale, Graphics Programmer at Arista Networks
Je suis Gizzy, un commis aux archives avec d'excellentes compétences interpersonnelles et de communication. Expert en nourriture , boisson et ...
RepRaimeCarrillo, Area Sales Manager at 247quickbookshelp
Hi, I am Raime from Tampa USA . I work as an Local account executive employee. I work in many fields ...
RepValerieRodri, Associate at Apache Design
I am a Medical equipment repairer in the Morehouse lab at the University of Wichita. I enjoy working with high-technology ...
RepOwenKary, Analyst at ASU
I am an experienced software engineer with a passion for java developing innovative programs that expedite the efficiency and effectiveness ...
RepMyraGreen, Accountant at 8x8
I am a dedicated secretary with 2 years of experience excited to join MCL to become a key player in ...
Reppetersmith36788, Animator at ABC TECH SUPPORT
I am working at Eden Lawn Service as a Bridge and lock tender . Here I manage all the things like ...
Replinhhonibh, Animator at ABC TECH SUPPORT
I am an experienced, officially certified driving instructor. Excellent driver with a great safety record. Encyclopedic knowledge of traffic rules ...
RepHeldaNate, Dev Lead at AMD
I am Helda , a certified Swimming Instructor capable of providing professional lessons and instructions on different swimming styles to various ...
Repblancalross748, Android Engineer at ABC TECH SUPPORT
Hello I am a Highly-professional and talented Managing Editor with a solid experience in planning and directing editorial activities for ...
RepEzraClark, Analyst at 8x8
I am an experienced multimedia journalist with a background in investigative reporting. I work well with photographers and videographers when ...
In Swift
- Rahul Jain May 20, 2018let setA:Set = [2, 10, 14, 19, 51, 71]
let setB:Set = [2, 9, 19, 40, 51]
let unionOfAandB = setA.union(setB)
for item in unionOfAandB
{
print("items is \(item)")
}