File IO Stream dengan sorting dan search
/**
* @(#)io_sort_search.java
*
* io_sort_search application
*
* @author
* @version 1.00 2012/6/20
*/
import java.io.*;
import java.util.*;
import java.util.Scanner;
public class io_sort_search {
public static void input(String s)
{
try
{
FileInputStream fstream = new FileInputStream("D:/tst.txt");
//Mengambil Data
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
String Isi_Baru ="";
int index_baris =0;
String source = "";
while ((strLine = br.readLine()) != null) {
source += strLine + "\n";
}
source += s;
char buffer[] = new char[source.length()];
source.getChars(0, source.length(), buffer, 0);
FileWriter f0 = new FileWriter("D:/tst.txt");
for (int i=0; i < buffer.length; i += 1) {
f0.write(buffer[i]);
}
f0.close();
} catch (Exception exp)
{
System.out.println(exp.toString());
}
}
public static void edit_baris(int pildata,String isi_sisipan,int baris_ke)
{
try
{
FileInputStream fstream = new FileInputStream("D:/tst.txt");
//Mengambil Data
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
String[] values;
//Membaca Perbaris
String Isi_Baru ="";
String baru="";
int index_baris =1;
while ((strLine = br.readLine()) != null) {
System.out.println(strLine.toString());
values = strLine.toString().split("#");
if(index_baris == baris_ke)
{
if(pildata==0)
{
values[0]= isi_sisipan.toString();
Isi_Baru+=values[0];
for(int x=1;x<values.length;x++)
{
Isi_Baru+=values[x];
}
Isi_Baru +="\n";
}else if(pildata==1)
{
values[0]= isi_sisipan.toString();
Isi_Baru+=values[0]+"#";
Isi_Baru+=values[1]+"#";
for(int x=2;x<values.length;x++)
{
Isi_Baru+="#"+values[x];
}
Isi_Baru +="\n";
}else if(pildata==2)
{
values[2]= isi_sisipan.toString();
Isi_Baru+=values[0]+"#";
Isi_Baru+=values[1]+"#";
Isi_Baru+=values[2]+"#";
for(int x=3;x<values.length;x++)
{
Isi_Baru+="#"+values[x];
}
Isi_Baru +="\n";
}else
{
Isi_Baru += strLine.toString();
Isi_Baru +="\n";
}
for(int x=0;x<values.length;x++)
{
System.out.println("data "+x+" : "+values[x]);
}
} else {
Isi_Baru+=strLine.toString();
Isi_Baru +="\n";
}
index_baris++;
}
char buffer[] = new char[Isi_Baru.length()];
Isi_Baru.getChars(0, Isi_Baru.length(), buffer, 0);
FileWriter f0 = new FileWriter("D:/tst.txt");
for (int i=0; i < buffer.length; i += 1) {
f0.write(buffer[i]);
}
f0.close();
} catch (Exception exp)
{
System.out.println(exp.toString());
}
}
public static void bubble_sort()
{
try{
//Membuka File
FileInputStream fstream = new FileInputStream("D:/tst.txt");
//Mengambil Data
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
String tampung;
int x = 0;
String[] values = new String[100];
while ((strLine = br.readLine()) != null) {
values[x] = (strLine.toString());
for (int xx=0;xx<=x;xx++)
{
for (int z=0;z<=x-1;z++)
{
if ((Integer.parseInt(values[z])) > (Integer.parseInt(values[z+1])))
{
tampung = values[z];
values [z] = values[z+1];
values[z+1] = tampung;
}
}
}
x++;
}
FileWriter f0 = new FileWriter("D:/tst.txt");
f0.write("");
f0.close();
for (int l = 0; l< x ; l++)
{
input(values[l]);
}
in.close();
}catch (Exception e){
//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}
public static void sequential_search(int cari)
{
try{
//Membuka File
FileInputStream fstream = new FileInputStream("D:/tst.txt");
//Mengambil Data
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
String tampung;
int x = 0;
//int cari;
boolean ada;
ada=false;
String[] values = new String[100];
while ((strLine = br.readLine()) != null) {
values[x] = (strLine.toString());
if ((Integer.parseInt(values[x])) == cari)
{
ada = true;
if(ada = true)
{
System.out.print(" ketemu di posisi "+(x+1));
}else
{
System.out.print("tidak ada");
}
}
x++;
}
FileWriter f0 = new FileWriter("D:/tst.txt");
f0.write("");
f0.close();
for (int l = 0; l< x ; l++)
{
input(values[l]);
}
in.close();
}catch (Exception e){
//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}
public static void cetak()
{
try{
//Membuka File
FileInputStream fstream = new FileInputStream("D:/tst.txt");
//Mengambil Data
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
String[] values;
//Membaca Perbaris
while ((strLine = br.readLine()) != null) {
// Cetak
System.out.println(strLine.toString());
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void hapus()
{
try
{
FileWriter f0 = new FileWriter("D:/tst.txt");
f0.write("");
f0.close();
} catch (Exception exp)
{
System.out.println(exp.toString());
}
}
public static void main(String[] args) {
Scanner rei=new Scanner(System.in);
for(int pilihan=1;pilihan<8;pilihan++)
{
System.out.println("===== MENU =====");
System.out.println("1.Input");
System.out.println("2.Edit");
System.out.println("3.Cetak");
System.out.println("4.Hapus");
System.out.println("5.Bubble Sort");
System.out.println("6.Sequential Search");
System.out.println("7.Keluar");
System.out.println("================");
System.out.println("Pilihan anda ?");
pilihan=rei.nextInt();
switch(pilihan)
{
case 1:
{
System.out.println("Masukan data yang anda inginkan ! ");
String data = rei.next();
input(data);System.out.println();
break;
}
case 2 :
{
System.out.println("Silahkan Masukkan Baris yang akan di Edit ! ");
int baris_nya = rei.nextInt();
//baris_edit(baris_nya);
System.out.println("Data keberapa yang ingin anda edit ? ");
System.out.println("Pilihan anda 0-2");
int data = rei.nextInt();
System.out.println("Silahkan Masukkan Kata ! ");
String kata = rei.next();
edit_baris(data,kata,baris_nya);System.out.println();
break;
}
case 3:
{
cetak();System.out.println();break;
}
case 4 :
{
hapus();System.out.println();break;
}
case 5 :
{
bubble_sort();System.out.println();break;
}
case 6 :
{
System.out.print("masukan data yang ingin dicari ");
int cari= rei.nextInt();
sequential_search(cari);System.out.println();break;
}
}
}
}
}
Selasa, 19 Juni 2012
Sabtu, 26 Mei 2012
Stream IO Pada Java
/**
* @(#)File_s.java
*
* File_s application
*
* @author
* @version 1.00 2012/5/26
*/
import java.io.*;
import java.util.*;
import java.util.Scanner;
public class File_s {
public static void input(String s)
{
try
{
FileInputStream fstream = new FileInputStream("D:/tst.txt");
//Mengambil Data
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
String Isi_Baru ="";
int index_baris =0;
String source = "";
while ((strLine = br.readLine()) != null) {
source += strLine + "\n";
}
source += s;
char buffer[] = new char[source.length()];
source.getChars(0, source.length(), buffer, 0);
FileWriter f0 = new FileWriter("D:/tst.txt");
for (int i=0; i < buffer.length; i += 1) {
f0.write(buffer[i]);
}
f0.close();
} catch (Exception exp)
{
System.out.println(exp.toString());
}
}
public static void edit_baris(int baris_ke, String isi_sisipan)
{
try
{
FileInputStream fstream = new FileInputStream("D:/tst.txt");
//Mengambil Data
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
String[] values;
//Membaca Perbaris
String Isi_Baru ="";
int index_baris =1;
while ((strLine = br.readLine()) != null) {
if (Isi_Baru != "")
{
Isi_Baru += "\n";
}
if(index_baris == baris_ke)
{
Isi_Baru += isi_sisipan.toString();
} else
{
Isi_Baru += strLine.toString();
}
index_baris++;
}
System.out.println(Isi_Baru);
char buffer[] = new char[Isi_Baru.length()];
Isi_Baru.getChars(0, Isi_Baru.length(), buffer, 0);
FileWriter f0 = new FileWriter("D:/tst.txt");
for (int i=0; i < buffer.length; i += 1) {
f0.write(buffer[i]);
}
f0.close();
} catch (Exception exp)
{
System.out.println(exp.toString());
}
}
public static void cetak()
{
try{
//Membuka File
FileInputStream fstream = new FileInputStream("D:/tst.txt");
//Mengambil Data
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
String[] values;
//Membaca Perbaris
while ((strLine = br.readLine()) != null) {
// Cetak
System.out.println(strLine.toString());
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void hapus()
{
try
{
FileWriter f0 = new FileWriter("D:/tst.txt");
f0.write("");
f0.close();
} catch (Exception exp)
{
System.out.println(exp.toString());
}
}
public static void main(String[] args) {
int pil = 0;
Scanner s = new Scanner(System.in);
while (pil != 5)
{
System.out.println("1. Input");
System.out.println("2. Edit");
System.out.println("3. Cetak");
System.out.println("4. Hapus");
System.out.println("Silahkan Masukkan Pilihan Anda ! ");
pil = s.nextInt();
switch (pil)
{
case 1 : {
System.out.println("Silahkan Masukkan Kata ! ");
String kata = s.next();
input(kata);
break;
}
case 2 : {
System.out.println("Silahkan Masukkan Baris yang akan di Edit ! ");
int baris_nya = s.nextInt();
System.out.println("Silahkan Masukkan Kata ! ");
String kata = s.next();
edit_baris(baris_nya,kata);
break;
}
case 3 : {
cetak();
break;
}
case 4 : {
hapus();
break;
}
default :{
break;
}
}
}
}
}
/**
* @(#)File_s.java
*
* File_s application
*
* @author
* @version 1.00 2012/5/26
*/
import java.io.*;
import java.util.*;
import java.util.Scanner;
public class File_s {
public static void input(String s)
{
try
{
FileInputStream fstream = new FileInputStream("D:/tst.txt");
//Mengambil Data
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
String Isi_Baru ="";
int index_baris =0;
String source = "";
while ((strLine = br.readLine()) != null) {
source += strLine + "\n";
}
source += s;
char buffer[] = new char[source.length()];
source.getChars(0, source.length(), buffer, 0);
FileWriter f0 = new FileWriter("D:/tst.txt");
for (int i=0; i < buffer.length; i += 1) {
f0.write(buffer[i]);
}
f0.close();
} catch (Exception exp)
{
System.out.println(exp.toString());
}
}
public static void edit_baris(int baris_ke, String isi_sisipan)
{
try
{
FileInputStream fstream = new FileInputStream("D:/tst.txt");
//Mengambil Data
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
String[] values;
//Membaca Perbaris
String Isi_Baru ="";
int index_baris =1;
while ((strLine = br.readLine()) != null) {
if (Isi_Baru != "")
{
Isi_Baru += "\n";
}
if(index_baris == baris_ke)
{
Isi_Baru += isi_sisipan.toString();
} else
{
Isi_Baru += strLine.toString();
}
index_baris++;
}
System.out.println(Isi_Baru);
char buffer[] = new char[Isi_Baru.length()];
Isi_Baru.getChars(0, Isi_Baru.length(), buffer, 0);
FileWriter f0 = new FileWriter("D:/tst.txt");
for (int i=0; i < buffer.length; i += 1) {
f0.write(buffer[i]);
}
f0.close();
} catch (Exception exp)
{
System.out.println(exp.toString());
}
}
public static void cetak()
{
try{
//Membuka File
FileInputStream fstream = new FileInputStream("D:/tst.txt");
//Mengambil Data
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
String[] values;
//Membaca Perbaris
while ((strLine = br.readLine()) != null) {
// Cetak
System.out.println(strLine.toString());
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void hapus()
{
try
{
FileWriter f0 = new FileWriter("D:/tst.txt");
f0.write("");
f0.close();
} catch (Exception exp)
{
System.out.println(exp.toString());
}
}
public static void main(String[] args) {
int pil = 0;
Scanner s = new Scanner(System.in);
while (pil != 5)
{
System.out.println("1. Input");
System.out.println("2. Edit");
System.out.println("3. Cetak");
System.out.println("4. Hapus");
System.out.println("Silahkan Masukkan Pilihan Anda ! ");
pil = s.nextInt();
switch (pil)
{
case 1 : {
System.out.println("Silahkan Masukkan Kata ! ");
String kata = s.next();
input(kata);
break;
}
case 2 : {
System.out.println("Silahkan Masukkan Baris yang akan di Edit ! ");
int baris_nya = s.nextInt();
System.out.println("Silahkan Masukkan Kata ! ");
String kata = s.next();
edit_baris(baris_nya,kata);
break;
}
case 3 : {
cetak();
break;
}
case 4 : {
hapus();
break;
}
default :{
break;
}
}
}
}
}
Rabu, 09 Mei 2012
EXTENDS EXCEPTION 2
TUGAS JAVA
file 1:
/**
* @(#)tugasjava.java
*
* tugasjava application
*
* @author
* @version 1.00 2012/5/10
*/
import java.util.Scanner;
public class tugasjava {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
int pil1;
try
{
System.out.println("Menu");
System.out.println("1. Input Grade ");
System.out.println("2. Input Angka");
System.out.print("pilihan anda ");
throw new exceptiontugas(pil1=input.nextInt());
}
catch(Exception exp)
{
System.out.print(exp.toString());
}
}
}
TUGAS JAVA
file 1:
/**
* @(#)tugasjava.java
*
* tugasjava application
*
* @author
* @version 1.00 2012/5/10
*/
import java.util.Scanner;
public class tugasjava {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
int pil1;
try
{
System.out.println("Menu");
System.out.println("1. Input Grade ");
System.out.println("2. Input Angka");
System.out.print("pilihan anda ");
throw new exceptiontugas(pil1=input.nextInt());
}
catch(Exception exp)
{
System.out.print(exp.toString());
}
}
}
file 2 dalam 1 project :
import java.util.Scanner;
public class exceptiontugas extends Exception
{
String pilihan;
exceptiontugas(int pil1)
{
switch(pil1)
{
case 1:
{
Scanner abc=new Scanner(System.in);
String grade= " ";
float nilai;
System.out.println("masukan nilai mahasiswa ");
nilai=abc.nextFloat();
if((nilai>=80)&&(nilai<=100))
grade="A";
else if((nilai>=68)&&(nilai<=79.99))
grade="B";
else if((nilai>=56)&&(nilai<=67.99))
grade="C";
else if((nilai>=45)&&(nilai<=55.99))
grade="D";
else if((nilai>0)&&(nilai<=44.99))
grade="E";
else if(nilai>100)
grade="nilai diluar range";
System.out.println(grade);break;
}
case 2:
{
Scanner def=new Scanner(System.in);
long total;
int x,y;
System.out.println("masukan angka ke satu");
x=def.nextInt();
System.out.println("masukan angka ke dua");
y=def.nextInt();
total=x/y;
if(total==0)
System.out.println("angka tidak dapat dibagi");
else if(total!=0)
System.out.println("total = "+total);break;
}
default:
{
System.out.println("pilihan cuman sampai 2");
}
}
}
public String toString()
{
return pilihan;
}
}
EXTENDS EXCEPTION
TUGAS JAVA
1. Buat CLASS EXCEPTION SENDIRI dengn format nama file nim_exp_milik_nama......jadi kalian buat 2 file dlam 1 project...
2. ISI exception adalah
-Nilai diluar batas/ diluar range yang ditentukan untuk program input nilai & cetak grade..... maksudny jika user memasukan sebuah nilai jika nilai tsb tidak ada dlm grade maka tampilkan "NILAI DILUAR RANGE "
-NIlai tidak dapat dibagi
untuk program yang menentukan 2 inputan bilngn jika bilngn ke 2 =0, munculkan error....mksudny user disuruh menginputkan 2 buah angka jika angka pertama dibagi dgn angka kedua hasilny 0 maka tampilkan pesan "angka tidak dpt dibagi"
-Pilihan tidak ditmukan/ menu tidak tersedia
program pemilihan menu.......maksudny kalian disuruh membuat sebuah menu yang berisikan 2 buah sub menu untuk mengakses data diatas, jika user memilih menu diluar dari dari sub menu diatas, maka tampilkan pesan error "LOE buta yee, menuny cuman ada 2" wkwkkwkwk
Tugas dikumpul minggu depan dalam bentuk PRINT OUT
1. Buat CLASS EXCEPTION SENDIRI dengn format nama file nim_exp_milik_nama......jadi kalian buat 2 file dlam 1 project...
2. ISI exception adalah
-Nilai diluar batas/ diluar range yang ditentukan untuk program input nilai & cetak grade..... maksudny jika user memasukan sebuah nilai jika nilai tsb tidak ada dlm grade maka tampilkan "NILAI DILUAR RANGE "
-NIlai tidak dapat dibagi
untuk program yang menentukan 2 inputan bilngn jika bilngn ke 2 =0, munculkan error....mksudny user disuruh menginputkan 2 buah angka jika angka pertama dibagi dgn angka kedua hasilny 0 maka tampilkan pesan "angka tidak dpt dibagi"
-Pilihan tidak ditmukan/ menu tidak tersedia
program pemilihan menu.......maksudny kalian disuruh membuat sebuah menu yang berisikan 2 buah sub menu untuk mengakses data diatas, jika user memilih menu diluar dari dari sub menu diatas, maka tampilkan pesan error "LOE buta yee, menuny cuman ada 2" wkwkkwkwk
Tugas dikumpul minggu depan dalam bentuk PRINT OUT
OK
Berikut Codingnya
file 1:
import java.util.Scanner;
public class tugas {
public static void main(String[] args)
{ Scanner input=new Scanner(System.in);
int pil;
try
{
System.out.println("Masukan pilihan anda");
System.out.println("1. Input Grade ");
System.out.println("2. Input Bilangan");
throw new nim_exp_milik_nama(pil=input.nextInt());
}
catch(Exception exp)
{
System.out.print(exp.toString());
}
}
}
file 2 tp dlam 1 project:
import java.util.Scanner;
class grademahasiswa
{ Scanner rei=new Scanner(System.in);
String grade= " ";float nilai;
void input()
{
System.out.println("masukan nilai mahasiswa ");
nilai=rei.nextFloat();
if((nilai>=80)&&(nilai<=100))
grade="A";
else if((nilai>=68)&&(nilai<=79.99))
grade="B";
else if((nilai>=56)&&(nilai<=67.99))
grade="C";
else if((nilai>=45)&&(nilai<=55.99))
grade="D";
else if((nilai>0)&&(nilai<=44.99))
grade="E";
else if(nilai>100)
grade="Anda Buta y, jelas-jelas nilai cuman sampai 100 ";
System.out.println(grade);
}
}
class bilangan
{ Scanner rei=new Scanner(System.in);
long total;
int angka1,angka2;
void ambil()
{
System.out.println("masukan bilangan pertama");
angka1=rei.nextInt();
System.out.println("masukan bilangan kedua");
angka2=rei.nextInt();
total=angka1/angka2;
if(total==0)
System.out.println("angka tidak dapat dibagi");
else if(total!=0)
System.out.println("total = "+total);
}
}
public class nim_exp_milik_nama extends Exception
{ grademahasiswa ubm=new grademahasiswa();
bilangan pelajar=new bilangan();
String pil;
nim_exp_milik_nama(int pil)
{
switch(pil)
{
case 1:
{
ubm.input();break;
}
case 2:
{
pelajar.ambil();break;
}
default:
{
System.out.println("GAK BACA Y?,pilihan cuman sampai 2");
}
}
}
public String toString()
{
return pil;
}
}
Senin, 07 Mei 2012
Guys Berikut Contoh Stack pada C++
STACK C++
#include <iostream.h>
#include <stdio.h>
#include <conio.h>
#include <string>
#define size 5
struct stack
{
int a[size];
int top;
};
typedef struct stack STACK;
void push(STACK *p,int value) /* PUSH OPERATION */
{
if(p->top==size-1)
cout<<"STACK IS FULL ";
else
p->a[++p->top]=value;
}
int pop(STACK *p) /* POP OPERATION */
{
if (p->top==-1)
{
cout<<"STACK IS EMPTY";
return -1;
}
else
return p->a[p->top--];
}
void display (STACK *p) /*DISPLAY OPERATION */
{ int i;
if(p->top==-1)
cout<<"\n STACK IS EMPTY\n";
else
cout<<"\nSTACK is\n";
for (i=p->top;i>=0; --i)
cout<<p->a[i]<<"\n";
}
void main()
{
STACK s ;
int x,c,i;
s.top=-1;
cout<<"---------- PROGRAM STACK USING STRUCT ----------"<<endl;
cout<<"------------- Name is Reinert Yosua ------------"<<endl;
cout<<"---------------- Id is 32110122 ----------------"<<endl;
cout<<endl;
system("pause");
clrscr();
do
{
cout<<"\n1: To PUSH\n";
cout<<"2: To POP\n";
cout<<"3: To Display\n";
cout<<"4: To Destroy\n";
cout<<"5: To Exit\n";
cout<<"\n\n Enter Choice\n";cin>>c;
switch(c)
{
case 1: cout<<"\nEnter Element: ";cin>>x;
push (&s,x);
break;
case 2: x=pop(&s);
if(x!=-1)
cout<<"\nElement deleted="<<x;
break;
case 3: display(&s);
break;
case 4: if(s.top==-1)
printf("\nSTACK IS EMPTY\n");
else
printf("\nSTACK is destroying\n");
for (i=s.top;i>=0; --i)
printf("element destroyed are %d\n",pop(&s));
s.top=-1;
} printf("\nSTACK DESTROYED\n");
}while(c!=5);cout<<"Thanks for using My Program and GBU"<<endl;
getch();
}
STACK C++
#include <iostream.h>
#include <stdio.h>
#include <conio.h>
#include <string>
#define size 5
struct stack
{
int a[size];
int top;
};
typedef struct stack STACK;
void push(STACK *p,int value) /* PUSH OPERATION */
{
if(p->top==size-1)
cout<<"STACK IS FULL ";
else
p->a[++p->top]=value;
}
int pop(STACK *p) /* POP OPERATION */
{
if (p->top==-1)
{
cout<<"STACK IS EMPTY";
return -1;
}
else
return p->a[p->top--];
}
void display (STACK *p) /*DISPLAY OPERATION */
{ int i;
if(p->top==-1)
cout<<"\n STACK IS EMPTY\n";
else
cout<<"\nSTACK is\n";
for (i=p->top;i>=0; --i)
cout<<p->a[i]<<"\n";
}
void main()
{
STACK s ;
int x,c,i;
s.top=-1;
cout<<"---------- PROGRAM STACK USING STRUCT ----------"<<endl;
cout<<"------------- Name is Reinert Yosua ------------"<<endl;
cout<<"---------------- Id is 32110122 ----------------"<<endl;
cout<<endl;
system("pause");
clrscr();
do
{
cout<<"\n1: To PUSH\n";
cout<<"2: To POP\n";
cout<<"3: To Display\n";
cout<<"4: To Destroy\n";
cout<<"5: To Exit\n";
cout<<"\n\n Enter Choice\n";cin>>c;
switch(c)
{
case 1: cout<<"\nEnter Element: ";cin>>x;
push (&s,x);
break;
case 2: x=pop(&s);
if(x!=-1)
cout<<"\nElement deleted="<<x;
break;
case 3: display(&s);
break;
case 4: if(s.top==-1)
printf("\nSTACK IS EMPTY\n");
else
printf("\nSTACK is destroying\n");
for (i=s.top;i>=0; --i)
printf("element destroyed are %d\n",pop(&s));
s.top=-1;
} printf("\nSTACK DESTROYED\n");
}while(c!=5);cout<<"Thanks for using My Program and GBU"<<endl;
getch();
}
Langganan:
Postingan (Atom)