Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Tema Saptamanii #4
- Obligatorii
- #include <iostream>
- using namespace std;
- struct nod{
- int info;
- nod *urm;
- };
- nod *prim=NULL, *ultim;
- void push(int x, nod *&prim){
- nod *p=new nod;
- if(prim==NULL){
- p->urm=NULL;
- p->info=x;
- prim=p;
- ultim=p;
- }
- else{
- p->info=x;
- p->urm=NULL;
- ultim->urm=p;
- ultim=p;
- }
- }
- void afis(){
- nod *p;
- for(p=prim;p!=NULL;p=p->urm)
- cout<<p->info<<" ";
- cout<<endl;
- }
- int pop(nod *&prim){
- nod *p;
- p=prim;
- int temp=p->info;
- prim=prim->urm;
- delete p;
- return temp;
- }
- bool eempty(nod *&prim){
- if(prim==NULL)
- return true;
- else
- return false;
- }
- int peek(nod *&prim){
- return prim->info;
- }
- int ssearch(int a, nod *&prim){
- int c=0,temp=-1;
- for(nod *p=prim;p!=NULL;p=p->urm){
- if(a==p->info)
- temp=c;
- c++;
- }
- if(temp==-1)
- return -1;
- else
- return temp;
- }
- int main()
- {
- nod *p=new nod;
- prim=NULL;
- push(1,prim);
- push(5,prim);
- push(6,prim);
- push(8,prim);
- push(34,prim);
- push(12,prim);
- afis();
- cout<<ssearch(1,prim);
- /* cout<<pop(prim)<<endl;
- if(eempty(prim))
- cout<<"Stiva e vida";
- else
- cout<<"Stiva nu e vida";
- cout<<peek(prim)<<endl;
- afis();*/
- return 0;
- }
- *******************************
- ???
- #include <iostream>
- using namespace std;
- struct nod{
- int info;
- nod *urm;
- };
- nod *prim=NULL, *ultim;
- void push(int x, nod *&prim){
- nod *p=new nod;
- if(prim==NULL){
- p->urm=NULL;
- p->info=x;
- prim=p;
- }
- else{
- p->info=x;
- p->urm=prim;
- prim=p;
- }
- }
- int ssearch(int a, nod *&prim){
- int c=0,temp=-1;
- for(nod *p=prim;p!=NULL;p=p->urm){
- if(a==p->info)
- temp=c;
- c++;
- }
- if(temp==-1)
- return -1;
- else
- cout<<temp<<endl;
- return temp;
- }
- void afis(){
- nod *p;
- for(p=prim;p!=NULL;p=p->urm){
- if(p->info==1)
- cout<<"a ";
- else
- cout<<"b ";
- }
- cout<<endl;
- }
- int pop(nod *&prim){
- nod *p;
- p=prim;
- int temp=p->info;
- prim=prim->urm;
- delete p;
- return temp;
- }
- bool eempty(nod *&prim){
- if(prim==NULL)
- return true;
- else
- return false;
- }
- int peek(nod *&prim){
- return prim->info;
- }
- int main()
- {
- nod *p=new nod;
- int n;
- char l;
- cout<<"n=";
- cin>>n;
- for(int i=0;i<n;i++){
- cin>>l;
- if(l=='a' && ssearch(0,prim)!=0)
- push(1,prim);
- if(l=='b')
- push(0,prim);
- }
- afis();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement