Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<windows.h>
- #include<conio.h>
- using namespace std;
- int br=0;
- struct elem
- {
- int key;
- elem *next;
- }*s1=NULL, *p, *s2=NULL;
- void push(int n, elem *&start);
- int pop(int &n,elem *&start);
- void insert();
- void insert()
- { SetConsoleCP(1251);SetConsoleOutputCP(1251);
- int n=1,size,i;
- size=1;
- cout<<"Въведете размер:\n";
- cin >> size;
- for (int i = 0; i < size; i++)
- {
- cout<<"Въведете число:\n";
- cin>>n;
- if (n!=0) push(n,s1);
- }
- }
- void push(int n, elem *&start)
- {
- p=start;
- start=new elem;
- start->key=n;
- start->next=p;
- br++;
- }
- int pop(int &n,elem *&start)
- {
- if(start)
- {
- n=start->key;
- p=start;
- start=start->next;
- delete p;
- return 1;
- }
- else
- {
- return 0;
- }
- }
- void main()
- {
- insert();
- int m, a;
- SetConsoleCP(1251);SetConsoleOutputCP(1251);
- do
- {
- cout<<"\n Въведи число между 1 и "<<br<<" !"<<endl;
- cout<<" M= ";
- cin>>m;
- }while(m<1 && m>br);
- for(int i=1;i<m;i++)
- {
- pop(a,s1);
- push(a,s2);
- }
- cout<<"\nВъведи нова стойност "<<endl;
- cout<<" A=\t";
- cin>>a;
- s1->key=a;
- while(pop(a,s2))
- push(a,s1);
- while(pop(a,s1))
- cout<<" "<<a<<"\t";
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement