Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // List1.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <iostream>
- using namespace std;
- struct list
- {
- int inf;
- list*next;
- };
- void init(list**begin,list**end, int n);
- void output(list*begin);
- void add_begin(list**begin, int n);
- void add_end(list**begin, int n);
- void add_prev(list**begin, int n, int x);
- void add_next(list**begin, int n, int x);
- int main()
- {
- list*begin = NULL, *end = NULL;
- int n, k, el, x;
- do
- {
- cout << "n = ";
- cin >> n;
- init(&begin, &end, n);
- cout << "Next ? ";
- cin >> k;
- } while (k != 0);
- cout << "el = ";
- cin >> el;
- add_begin(&begin, el);
- cout << "el = ";
- cin >> el;
- add_end(&begin, el);
- cout << "el = ";
- cin >> el;
- cout << "x = ";
- cin >> x;
- add_prev(&begin, el, x);
- cout << "el = ";
- cin >> el;
- cout << "x = ";
- cin >> x;
- add_next(&begin, el, x);
- cout << "List: ";
- output(begin);
- system("pause");
- return 0;
- }
- void init(list**begin, list**end, int n)
- {
- list*t = new list;
- if (*begin == NULL)
- {
- t->inf = n;
- t->next = NULL;
- *begin = *end = t;
- }
- else
- {
- t->inf = n;
- t->next = NULL;
- (*end)->next = t;
- *end = t;
- }
- }
- void output(list*begin)
- {
- list*t = new list;
- t = begin;
- while (t != NULL)
- {
- cout << t->inf << " ";
- t = t->next;
- }
- cout << endl;
- }
- void add_begin(list**begin, int n)
- {
- list*t = new list;
- t->inf = n;
- t->next = *begin;
- *begin = t;
- }
- void add_end(list**begin, int n)
- {
- list*t = new list;
- t = *begin;
- while (t != NULL)
- {
- t = t->next;
- }
- list*a = new list;
- a->next = NULL;
- a->inf = n;
- t->next = a;
- }
- void add_prev(list**begin, int n, int x)
- {
- }
- void add_next(list**begin, int n, int x)
- {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement