ыыы_ыы

← разместить еще код

Расшаренный код:

#include <iostream>
using namespace std;

struct Node {
  int data;
  Node *next;
};

Node *head = NULL;
Node *tail = NULL;

void find_tail() {
  Node *local_node = head;
  while (1) {
    if (local_node->next == NULL) {tail = local_node; break;}
    else local_node = local_node->next;
  }
}

void push_b(int d) {
  Node *newNode = new Node;
  newNode->data = d;
  newNode->next = NULL;
  if (head == NULL) head = newNode;
  else {
    find_tail();
    Node *tailNode = tail;
    tailNode->next = newNode;
  }
}


void push_f(int d) {
  Node *newNode = new Node;
  newNode->data = d;
  newNode->next = head;
  if (head == NULL) tail = newNode;
  head = newNode;
}


void pop_b() {
  Node *current = head;
  while (1){
    if (current->next->next == NULL) break;
    current = current->next;
  }
  current->next = NULL;
  tail = current;
}


void pop_f() {
  Node *current = head;
  head = current->next;
}


void show() {
  Node *current = head;
  while(current) {
    cout << current->data << endl;
    current = current->next;
  }
}

void del() {
  Node *current = head;
  while (current) {
    Node *to_delete = current;
    current = current->next;
    delete(to_delete);
  }
}

void pop_i(int i) {
  Node *current = head;
  int j = 0;
  Node *pre = head;
  Node *post = head
  while(current) {
    j += 1;
    if (j == i-1) pre = current;
    if (j == i+1) post = current;
    current = current->next;
  }
  pre->next = post;
}

int main()
{
  push_b(10);
  show();
  del();
  show();
  return 0;
}