Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- int counter = 0;
- int countele = 0;
- template<typename Key, typename Info>
- class sequence{
- private:
- struct element{
- Key k;
- Info i;
- element *next;
- };
- element *head;
- public:
- void push_front(const Key &k, const Info &i);
- void push_back(const Key &k, const Info &i);
- void pop_front();
- void pop_back();
- void clear();
- void deleteKey(const Key &k);
- sequence();
- ~sequence();
- sequence(const sequence<Key, Info> & copy);
- void print();
- };
- template<typename Key, typename Info>
- sequence<Key,Info>::sequence(){
- head=NULL;
- counter++;
- }
- template<typename Key, typename Info>
- sequence<Key,Info>::sequence(const sequence<Key, Info> & copy){
- element *temp = copy.head;
- this->head = NULL;
- while(temp){
- this->push_back(temp->k, temp->i);
- temp = temp->next;
- }
- }
- template<typename Key, typename Info>
- void sequence<Key, Info>::deleteKey(const Key &k){
- element *temp;
- }
- template<typename Key, typename Info>
- sequence<Key,Info>::~sequence(){
- clear();
- counter--;
- }
- template<typename Key, typename Info>
- void sequence<Key,Info>::print(){
- element *temp = head;
- while(temp!=NULL){
- cout<<"key: "<<temp->k<<" info: "<<temp->i<<endl;
- temp = temp->next;
- }
- cout<<"---------------------"<<endl;
- }
- template<typename Key, typename Info>
- void sequence<Key,Info>::clear(){
- element *temp = head;
- while(head!=NULL){
- head = head->next;
- delete temp;
- temp = head;
- countele--;
- }
- }
- template<typename Key, typename Info>
- void sequence<Key, Info>::push_front(const Key &k, const Info &i){
- element *temp;
- temp = new element;
- temp->k = k;
- temp->i = i;
- temp->next = head;
- head = temp;
- countele++;
- }
- template<typename Key, typename Info>
- void sequence<Key, Info>::push_back(const Key &k, const Info &i){
- element *temp;
- temp = new element;
- temp->k = k;
- temp->i = i;
- temp->next = NULL;
- element *tmp = head;
- if(head == NULL){
- head = temp;
- countele++;
- cout<<"pusta glowa"<<endl;
- }
- else{
- while(tmp->next){
- tmp = tmp->next;
- }
- tmp->next = temp;
- cout<<"TEST"<<endl;
- countele++;
- }
- }
- template<typename Key, typename Info>
- void sequence<Key, Info>::pop_front(){
- if(head==NULL){
- return;
- }
- element *temp = head;
- head = head->next;
- delete temp;
- countele--;
- }
- template<typename Key, typename Info>
- void sequence<Key, Info>::pop_back(){
- if(head==NULL){
- return;
- }
- element *temp = head;
- if(head->next == NULL){
- delete temp;
- head = NULL;
- countele--;
- return;
- }
- else{
- element *prev;
- while(temp->next){
- prev = temp;
- temp = temp->next;
- }
- delete temp;
- prev->next = NULL;
- countele--;
- }
- }
- int main(){
- sequence<unsigned,string> s;
- s.push_front(1,"jeden");
- s.push_front(2,"dewa");
- s.push_front(3,"terzy");
- s.push_back(4, "tsztery");
- cout<<countele<<endl;
- cout<<counter<<endl;
- s.print();
- s.pop_front();
- cout<<countele<<endl;
- cout<<counter<<endl;
- s.print();
- s.clear();
- cout<<countele<<endl;
- cout<<counter<<endl;
- s.print();
- s.pop_front();
- cout<<countele<<endl;
- cout<<counter<<endl;
- s.print();
- s.push_back(5, "pienc");
- cout<<countele<<endl;
- cout<<counter<<endl;
- s.print();
- s.clear();
- s.push_front(7,"jed7en");
- s.push_front(58,"dew785a");
- s.push_front(38,"ter875zy");
- s.push_front(14,"je785en");
- s.push_front(12,"de8wa");
- s.push_front(32,"ter785");
- s.print();
- s.pop_back();
- s.pop_front();
- s.print();
- s.clear();
- s.pop_back();
- s.print();
- s.pop_front();
- s.print();
- s.push_back(6,"ref");
- s.print();
- s.pop_back();
- s.print();
- s.push_front(99,"sf");
- s.print();
- s.pop_front();
- s.print();
- cout<<countele<<endl;
- cout<<counter<<endl;
- s.clear();
- s.push_back(14,"je785en");
- s.push_back(12,"de8wa");
- s.push_back(32,"ter785");
- s.print();
- cout<<countele<<endl;
- cout<<counter<<endl;
- sequence<unsigned,string> c(s);
- c.print();
- cout<<countele<<endl;
- cout<<counter<<endl;
- //a=+b;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement