Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save gunaytemur/966e648d9038188f66c31ea67044cc65 to your computer and use it in GitHub Desktop.
Save gunaytemur/966e648d9038188f66c31ea67044cc65 to your computer and use it in GitHub Desktop.
Data Structure C++
Yığın dizi uygulaması (Stack array implementation)
@gunaytemur
Copy link
Author

#include"iostream"
using namespace std;
int dizi[5];
int top=-1;

void push(int x){
if(top==4)
cout<<"stack dolu";
else
{
//top++;
//dizi[top]=x;
dizi[++top]=x;
}
}

void hesapla(int x){
int y=10;
int top=x+y;
cout<<"hesapladi-sonuc:"<<top<<endl;
}

void pop(){

int data;
if(top==-1)
	cout<<"stack bos";
else
{
	data=dizi[top];
	top--;
	hesapla(data);
}

}

void yazdir(){

for(int i=top;i>=0;i--)
	cout<<dizi[i]<<" ";

}
void main(){
push(3);
push(7);
push(8);
push(12);
push(15);
push(11);
yazdir();
system("pause");
pop();
pop();
yazdir();
pop();
pop();
pop();
cout<<endl;
system("pause");
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment