Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- struct node {
- int val;
- node *next;
- };
- void add(node*& H, int x ) {
- node * p = new node;
- p->val = x;
- p->next = H;
- H=p;
- }
- int size(node* H) {
- int size = 0;
- while(H != NULL) {
- H = H->next;
- size++;
- }
- return size;
- }
- void show(node* H) {
- node * p = H;
- cout <<"HEAD->";
- while(p != NULL) {
- cout << p->val <<"->";
- p = p->next;
- }
- cout << "NULL"<<endl;
- }
- void delTop(node*& H) {
- if( H != NULL) {
- node *p = H;
- H = p->next;
- delete p;
- }
- }
- void delX(node*& H, int x) {
- if(H != NULL) {
- node *p = H;
- if(H->val == x) {
- delTop(H);
- } else {
- while(p->next != NULL && p->next->val != x) {
- p = p->next;
- }
- if(p->next != NULL) {
- delTop(p->next);
- }
- }
- }
- }
- void delEverySecondElement(node*& H) {
- delTop(H);
- node *p = H;
- node *p2 = H;
- while(p != NULL && p->next != NULL) {
- p = p->next;
- p2->next = p->next;
- p2 = p2->next;
- delete p;
- p = p2;
- }
- }
- void copyNumberBehindIfisEven(node*& H) {
- node *p = H;
- node *p2 = H;
- while(p != NULL && p->next != NULL) {
- if(p->val%2 == 0) {
- cout << p->val;
- }
- p = p->next;
- }
- }
- bool isEmpty(node* H) {
- if(H !=NULL) {
- return 0;
- } else {
- return 1;
- }
- }
- void top(node* H) {
- if(H!=NULL) {
- cout << H->val << endl;
- } else {
- cout << "empty";
- }
- }
- void push() {}
- void pop() {}
- int main()
- {
- node *H = NULL;
- add(H, 12);
- add(H, 17);
- add(H, 18);
- add(H, 20);
- add(H, 22);
- add(H, 24);
- add(H, 2);
- add(H, 4);
- add(H, 6);
- show(H);
- cout << "Rozmiar: " << size(H) << endl;
- delEverySecondElement(H);
- show(H);
- copyNumberBehindIfisEven(H);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement