Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdlib.h>
- using namespace std;
- struct node
- {
- int data;
- node* link;
- };
- void check(node* h);
- int menu(node* h);
- void pozicija(node* h);
- void newlist(node* h);
- void change (node* h);
- int trint (node*& h);
- void cls()
- {
- system ("CLS");
- }
- int main()
- {
- node* h=NULL;
- menu(h);
- return 0;
- }
- void check(node* h)
- {
- int i=1;
- node* temp;
- temp=h;
- if (h!=NULL) {
- do{
- cout<<"Saraso skaicius "<<i<<": "<<temp->data<<endl;
- temp=temp->link;
- i++;
- }while(temp->link!=NULL);
- cout<<"Saraso skaicius "<<i<<": "<<temp->data<<endl<<endl<<endl;
- }
- else
- { cls();
- cout<<"Sarasas neegzistuoja\n\n";
- }
- }
- int menu(node* h)
- {
- int i=0;
- cout<<"pasirinkite funkcija: \n\n0) Isjungti programa\n1) atspausdinti sarasa\n2) iterpti nauja elementa i nurodyta pozicija\n3) iterpti elementa vietoj tam tikro elemento\n4) Sukurti nauja sarasa\n5) Istrinti dabartini sarasa\n"<<endl;
- cin>>i;
- if (i==0) {exit(0);}
- if (i==1) {cls();check(h);menu(h);}
- if (i==2) {cls();check(h);pozicija(h);menu(h);}
- if (i==3) {cls();check(h);change(h);menu(h);}
- if (i==4) {cls();newlist(h);}
- if (i==5) {cls();trint(h);menu(h);}
- else {cls();menu(h);}
- }
- void pozicija(node* h)
- {
- int a,b,i;
- cout<<"Pasirinkite i kuria pozicija norite iterpti skaiciu: ";cin>>a;
- cout<<"Iveskite savo skaiciu: ";cin>>b;
- node* temp;
- node* l;
- temp=h;
- for (i=2;i<=a && temp!=NULL;i++)
- {
- l=temp;
- temp=temp->link;
- if (a==i)
- {
- node* temp1=new node;
- temp1->data=b;
- temp1->link=temp;
- l->link=temp1;
- }
- }
- cls();
- }
- void newlist(node* h)
- {
- int i,ii;
- node* l;
- if (h==NULL){
- node* temp=new node;
- l=temp;
- cout<<"Iveskite kiek bus skaiciu sarase: ";cin>>ii;
- for(i=0;i<ii;i++)
- {
- node* temp1=new node;
- cout<<"iveskite "<<i+1<<" skaiciu: ";
- cin>>temp1->data;
- temp1->link=NULL;
- if (i==0)
- {
- h=temp1;
- }
- else
- {
- l->link=temp1;
- }
- l=temp1;
- }
- cls();
- }else{cout<<"Sarasas jau egzistuoja, pirmiausia reikia ji istrinti\n\n}";}
- menu(h);
- }
- void change(node* h)
- {
- int a,b,c=0;
- cout<<"Iveskite skaiciu kuri norite pakeisti: ";cin>>a;
- cout<<"Iveskite skaiciu kuriuo norite pakeisti: ";cin>>b;
- cls();
- int i=1;
- node* temp;
- temp=h;
- if (h!=NULL)
- {
- while(temp->link!=NULL)
- {
- if (a==temp->data)
- {
- temp->data=b;
- c=1;
- cout<<"Rastas skaicius "<<a<<" jis pakeistas skaiciu: "<<temp->data<<endl;
- }
- temp=temp->link;
- i++;
- }
- if (a==temp->data)
- {
- temp->data=b;
- c=1;
- cout<<"Rastas skaicius "<<a<<" jis pakeistas skaiciu: "<<temp->data<<endl;
- }
- }
- if (h==NULL)
- {
- cls();
- cout<<"Sarasas neegzistuoja"<<endl;
- }
- if (c==0)
- {
- cout<<"Skaicius nerastas...\n"<<endl;
- }
- }
- int trint(node*& h)
- {
- node* kitas;
- node* temp=h;
- temp=h;
- while (temp->link!=NULL)
- {
- kitas=temp->link;
- delete temp;
- temp=kitas;
- }
- delete temp;
- h=NULL;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement