Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct node {
- int data;
- char charData;
- struct node *next;
- };
- typedef struct node NODE;
- struct node *head = new NODE();
- void insert(NODE *val) {
- struct node *temp = new struct node();
- if(head->next == NULL) {
- temp->data = val->data;
- temp->charData = val->charData;
- temp->next = NULL;
- head->next = temp;
- } else {
- temp = head;
- NODE *flag = new NODE();
- while (temp->next != NULL) {
- temp = temp->next;
- }
- flag->data = val->data;
- flag->charData = val->charData;
- flag->next = NULL;
- temp->next = flag;
- }
- }
- void display() {
- NODE *temp = head;
- while(temp->next != NULL) {
- printf("%c: %d\n", temp->next->charData, temp->next->data);
- temp = temp->next;
- }
- printf("\n");
- }
- void countPrint(char abc) {
- NODE *temp = head;
- while(temp->next != NULL) {
- if (abc == temp->next->charData) {
- temp->next->data++;
- break;
- }
- temp = temp->next;
- }
- }
- int main() {
- int balChal = 26, count = 0;
- char name = 'a';
- string str;
- cin >> str;
- for (int i = 0; i < str.length(); i++) {
- str[i] = tolower(str[i]);
- }
- while (balChal--) {
- NODE *a = new NODE();
- a->data = count;
- a->charData = name;
- name++;
- insert(a);
- }
- for (int i = 0; i < str.length(); i++) {
- countPrint(str[i]);
- }
- display();
- }
Advertisement
Add Comment
Please, Sign In to add comment