-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstackAlphaxNum.cpp
More file actions
70 lines (68 loc) · 1.21 KB
/
stackAlphaxNum.cpp
File metadata and controls
70 lines (68 loc) · 1.21 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include<iostream>
using namespace std;
struct AN
{
char *data;
int top,size;
void init(int n)
{
size=n;
data=new char[size];
top=-1;
}
bool isempty()
{return top==-1;}
bool isfull()
{return top==size-1;}
void push(char c)
{
if(isfull())return;
data[++top]=c;
}
char pop()
{
if(isempty())return'\0';
return data[top--];
}
};
int getlength(char a[])
{
int i=0;
while(a[i]!='\0')
i++;
return i;
}
int main()
{
AN s,s1,s2,s3;
char a[100];
fgets(a,100,stdin);
int len=getlength(a);
if(a[len-1]=='\n')
{
a[len-1]='\0';
len--;
}
cout<<"original word: ";
for(int i=0;i<len;i++)
{
cout<<a[i];
}
cout<<endl;
s.init(len);s1.init(len);s2.init(len);s3.init(len);
for(int i=0;i<len;i++)
s.push(a[i]);
while(!s.isempty())
{
char c=s.pop();
if(isalpha(c))s1.push(c);
else if(isdigit(c))s2.push(c);
else s3.push(c);
}
cout << "Alphabets: ";
while(!s1.isempty()) cout << s1.pop();
cout << "\nDigits: ";
while(!s2.isempty()) cout << s2.pop();
cout<<"\nrest characters: ";
while(!s3.isempty()) cout<< s3.pop();
}