Skip to content

Commit 3bcc47b

Browse files
authored
Merge pull request kothariji#756 from anujpophali/master
added byteStuffing.cpp in networking
2 parents c12fa81 + f5cec1a commit 3bcc47b

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
int Solution::maxSubArray(const vector<int> &A) {
2+
int maxi = INT_MIN;
3+
int sum = 0;
4+
for(int i = 0; i < A.size(); i++){
5+
sum = sum + A[i];
6+
maxi = max(maxi, sum);
7+
if(sum < 0) sum = 0;
8+
}
9+
return maxi;
10+
}

Networking/byteStuffing.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
string stuff(string s, int fsz);
5+
void deStuff(string s);
6+
7+
int main(){
8+
string st, s;
9+
int fsz;
10+
cout << "Enter the data := ";
11+
cin >> s;
12+
cout << "Enter the frame size := ";
13+
cin >> fsz;
14+
st = stuff(s, fsz);
15+
deStuff(st);
16+
return 0;
17+
}
18+
19+
string stuff(string s, int fsz){
20+
int nof, n;
21+
string st;
22+
nof = (s.size()/(fsz-2))+1;
23+
n = s.size() + nof*2;
24+
int indx = 0;
25+
bool flag = false;
26+
for(int i = 0; i < n; i++){
27+
if(i%fsz==0) st+='#';
28+
else if(i%fsz==fsz-1) st+='#';
29+
else{
30+
if(s[indx]=='\0'){
31+
flag = true;
32+
break;
33+
}
34+
st+=s[indx];
35+
indx++;
36+
}
37+
}
38+
if(flag) st += '#';
39+
cout << "Stuffed data := " << st << "\n";
40+
return st;
41+
}
42+
43+
void deStuff(string s){
44+
string deSt;
45+
for(int i = 0; i < s.size(); i++){
46+
if(s[i]!='#') deSt+=s[i];
47+
}
48+
cout << "DeStuffed data := " << deSt << "\n";
49+
}

0 commit comments

Comments
 (0)