PROGRAM MENGGABUNGKAN 2 STACK MENJADI 1
01.44
By
Unknown
PROGRAMKE-1
0
komentar
#include <iostream>
#include <conio.h>
using namespace std;
struct node{
char data;
node *next;
};
void stack1(int x,int banyak,node *temp,node *top,node *isi){
//stack3(x,banyak,temp,top,isi);
if(banyak==0){
isi=temp;
isi->next=NULL;
}else{
temp->next=isi;
isi=temp;
}
banyak++;
if(x<=5){
cout<<x<<" ";
}
}
void stack2(int x,int banyak,node *temp,node *top,node *isi){
if(banyak==0){
isi=temp;
isi->next=NULL;
}else{
temp->next=isi;
isi=temp;
}
banyak++;
if(x>5){
cout<<x<<" ";
}
}
void stack3(int x,int banyak,node *temp,node *top,node *isi){
stack1(x,banyak,temp,top,isi);
stack2(x,banyak,temp,top,isi);
}
int main(){
int banyak,x;
banyak=0;
node *isi;
node*top;
node *temp;
temp =new node;
temp->data=x;
temp->next=NULL;
top=temp;
cout<<"Stack 1 = ";
for(int i=1;i<=10;i++){
stack1(i,banyak,temp,top,isi);
}
cout<<endl<<endl<<"Stack 2 = ";
for(int i=1;i<=10;i++){
stack2(i,banyak,temp,top,isi);
}
cout<<endl<<endl<<"Stack 3 = ";
for(int i=1;i<=10;i++){
stack3(i,banyak,temp,top,isi);
}
getch();
}
#include <conio.h>
using namespace std;
struct node{
char data;
node *next;
};
void stack1(int x,int banyak,node *temp,node *top,node *isi){
//stack3(x,banyak,temp,top,isi);
if(banyak==0){
isi=temp;
isi->next=NULL;
}else{
temp->next=isi;
isi=temp;
}
banyak++;
if(x<=5){
cout<<x<<" ";
}
}
void stack2(int x,int banyak,node *temp,node *top,node *isi){
if(banyak==0){
isi=temp;
isi->next=NULL;
}else{
temp->next=isi;
isi=temp;
}
banyak++;
if(x>5){
cout<<x<<" ";
}
}
void stack3(int x,int banyak,node *temp,node *top,node *isi){
stack1(x,banyak,temp,top,isi);
stack2(x,banyak,temp,top,isi);
}
int main(){
int banyak,x;
banyak=0;
node *isi;
node*top;
node *temp;
temp =new node;
temp->data=x;
temp->next=NULL;
top=temp;
cout<<"Stack 1 = ";
for(int i=1;i<=10;i++){
stack1(i,banyak,temp,top,isi);
}
cout<<endl<<endl<<"Stack 2 = ";
for(int i=1;i<=10;i++){
stack2(i,banyak,temp,top,isi);
}
cout<<endl<<endl<<"Stack 3 = ";
for(int i=1;i<=10;i++){
stack3(i,banyak,temp,top,isi);
}
getch();
}
0 komentar: