Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include "stdafx.h"
- #include <iostream>
- using namespace std;
- typedef char newtp;
- struct node
- {
- newtp data;
- node* next;
- node* pred;
- };
- class linklist
- {
- private:
- node* first;
- public:
- linklist() { first = NULL; }
- void push(newtp d, int pos);
- int pop(int pos);
- void clean();
- void view();
- };
- void linklist::push(newtp d, int pos)
- {
- node* newnode = new node;
- newnode->data = d;
- if (first == NULL)
- {
- newnode->next = newnode;
- newnode->pred = newnode;
- first = newnode;
- }
- else
- {
- node* temp = first;
- for (int i = pos; i > 1; i--, temp = temp->next);
- temp->pred->next = newnode;
- newnode->pred = temp->pred;
- newnode->next = temp;
- temp->pred = newnode;
- }
- }
- int linklist::pop(int pos)
- {
- if (first == NULL) return 0;
- int val;
- if (first == first->next)
- {
- val = first->data;
- delete first;
- first = NULL;
- }
- else
- {
- node* temp = first;
- for (int i = pos; i > 1; i--, temp = temp->next);
- if (temp == first) first = temp->next;
- temp->pred->next = temp->next;
- temp->next->pred = temp->pred;
- val = temp->data;
- delete temp;
- }
- return val;
- }
- void linklist::clean()
- {
- if (first == NULL) return;
- for (node* newnode = first->next; newnode != first; newnode = newnode->next) delete newnode;
- delete first;
- first = NULL;
- }
- void linklist::view()
- {
- if (first == NULL) return;
- node* newnode = first;
- do
- {
- cout << newnode->data;
- newnode = newnode->next;
- } while (newnode != first);
- }
- int main()
- {
- setlocale(0,"");
- linklist li;
- char str[] = "dedededed";
- char b[255];
- char* pch = strtok(str, " ");
- while (pch != NULL)
- {
- char _ch = pch[0];
- for (int i = 1; i < strlen(pch); ++i)
- {
- if (pch[i] == _ch)
- {
- pch[i] = 'G';
- }
- }
- pch = strtok(NULL, " ");
- }
- for (int i = 0; i < strlen(str); i++)
- {
- b[i] = *(str+i);
- }
- for (int i = 0; i < strlen(str); i++)
- {
- if (b[i] != 'G'){
- li.push(b[i], i+1);
- }
- }
- li.view();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement