File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -102,3 +102,8 @@ This is a repository containing various C++ Programs to understand the basic con
102
102
103
103
C++ Code for finding the second largest element present in the given array.
104
104
105
+ * [ First Non-Repeating Character in an String] ( https://github.com/altruistcoder/Data-Structures-Python/blob/master/first_non_repeating_character.cpp ) :
106
+
107
+ C++ Code for finding the first non-repeating character present in the given string.
108
+
109
+
Original file line number Diff line number Diff line change
1
+ # include < iostream>
2
+ #define NO_OF_CHARS 256
3
+ using namespace std ;
4
+
5
+ int firstNonRepeating (char *str)
6
+ {
7
+ int i;
8
+ int *freq = new int [NO_OF_CHARS];
9
+ for (i=0 ; *(str+i); i++)
10
+ freq[*(str+i)]++;
11
+ cout<<endl;
12
+ for (i=0 ; *(str+i); i++)
13
+ {
14
+ if (freq[*(str+i)] == 1 )
15
+ {
16
+ return i;
17
+ }
18
+ }
19
+ return -1 ;
20
+ }
21
+
22
+ int main ()
23
+ {
24
+ char str[256 ];
25
+ cout<<" Enter a string: " ;
26
+ cin>>str;
27
+ int r = firstNonRepeating (str);
28
+ if (r == -1 )
29
+ cout<<" No non-repeating character present in given string. Either all of the characters are repeating or string is empty" ;
30
+ else
31
+ cout<<" First non-repeating character present in given string: " <<str[r];
32
+ return 0 ;
33
+ }
You can’t perform that action at this time.
0 commit comments