-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSingleton2.cpp
More file actions
50 lines (38 loc) · 1.11 KB
/
Singleton2.cpp
File metadata and controls
50 lines (38 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// create singleton design pattern with 2 classes
// 1. Singleton class
#Include <iostream.h>
#Include <conio.h>
#Include <string.h>
#Include <stdlib.h>
#Include <stdio.h>
class Singleton {
private static Singleton instance;
private Singleton() {}
public static Singleton getInstance() {
if (instance == null) {
instance = new Singleton();
}
return instance;
}
public void print() {
System.out.println("Singleton class");
}
public static void main(String[] args) {
Singleton s1 = Singleton.getInstance();
Singleton s2 = Singleton.getInstance();
s1.print();
s2.print();
}
// linear search alogrithm in c++
public static int search(String[] array, String str) {
for (int i = 0; i < array.length; i++) {
if (array[i].equals(str)) { return i; }
}
return -1;
}
// take input for array to be searched
public static String[] inputArray() {
int searcharrlength = 0; //length of search array
int array[searcharrlength];
//take input for array to be searched
}