ഡിസംബർ 21, 2012

Netbeans java with mysql












import java.sql.*;
import javax.swing.table.DefaultTableModel;
import javax.swing.JOptionPane; *//*
SEE  BUTTON
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)
{
try
{
Class.forName("java.sql.DriverManager");
Connection con = (Connection)
DriverManager.getConnection("jdbc:mysql://localhost:3306/telephone","root","firoz");
Statement stmt = (Statement) con.createStatement();
String query = "SELECT * from dir" + ";";
ResultSet rs = stmt.executeQuery(query);
while(rs.next())
{
int  a=Integer.parseInt(rs.getString("did"));
String b=rs.getString ("ph");
String c=rs.getString ("dname");
DefaultTableModel m=(DefaultTableModel)jTable1.getModel();
Object [] ob={a,c,b};
m.addRow(ob);
}
}
catch (Exception e)
{
JOptionPane.showMessageDialog (this, e.getMessage());
e.printStackTrace();
}    
    }

മേയ് 05, 2012

Notes On Stack Queue & Linked List



Notes On Stack Queue & Linked List
1) Linked List ,Stack, Queue
#include<iostream.h>
#include<conio.h>
#include<process.h>
struct node
{ int n;
node*link;
}*start,*newptr,*save,*ptr,*rear;
void insertBeg(int x) //  1)  in Linked List and Stack
{       ptr=new node;
ptr->n=x;
ptr->link=NULL;
if(start==NULL)
start=ptr;
else
{ save=start;
start=ptr;
ptr->link=save;
}
}
void insertEnd(int x) // 2) in Linked List and Queue
{ ptr=new node;
ptr->n=x;
ptr->link=NULL;
if(start==NULL)
start=rear=ptr;
else
{ rear->link=ptr;
rear=ptr;
}
}
void deletetop() //3) in Linked List, Stack & Queue
{ if(start==NULL)
cout<<“\n Underflow”;
else
{ ptr=start;
start=start->link;
delete ptr;
}
}
void disp(node *np) // 4)in Linked List, Stack & Queue
{ while(np!=NULL)
{ cout<<“ -> “<<np->n;
np=np->link;
}
}
void main()
{ start=rear=NULL;
int e;
clrscr();
int sl;
char ch;
do{
clrscr();
cout<<“\n\tMENU\n”;
cout<<“ 1. INSERTION Begnig of list\n”;
cout<<“ 2. INSERTION End of list\n”;
cout<<“ 3. deletion\n”;
cout<<“ 4.display\n”;
cout<<“ 5. exIT\n”;
cout<<“\nEnter Ur selection\n”;
cin>>sl;
switch(sl)
{ case 1: cout<<“Enter Element to be inserted”;
cin>>e;
insertBeg(e);
break;
case 2: cout<<“Enter Element to be inserted”;
cin>>e;
insertEnd(e);
break;
case 3: deletetop();
break;
case 4:disp(start);
break;
case 5: cout<<“ U R Xit from HERe “;
getch();
exit(0);
break;
default:
cout<<“ Invalid Selection”;
}
cout<<“\nDo U want 2 continue (y/n)? “;
cin>>ch;
}while(ch==’y’||ch==’Y’);
getch();
} 2)Array stack
#include<iostream.h>
#include<conio.h>
#include<process.h>
void push(int stack[],int &top,int s,int e) //5)
{ if(top==s-1)
cout<<“\nOver flow”;
else
{ top++;
stack[top]=e;
}
}
void pop(int stack[],int &top) //6)
{ if(top==-1)
cout<<“Underflow”;
else
{ cout<<“Deleted element is “<<stack[top];
top—;
}
}
void disp(int stack[],int top) //7)
{ cout<<“ \n Elements in Stack is :\n”;
for(int i=top;i>=0;i—)
cout<<stack[i]<<“\n “;
}
void main()
{ int stack[50],s=50,top=-1,e;
clrscr();
int sl;
char ch;
do{
clrscr();
cout<<“MENU\n”;
cout<<“ 1. INSERTION\n”;
cout<<“ 2. deletion\n”;
cout<<“3.display\n”;
cout<<“ 4. exIT\n”;
cout<<“eNTER SELECTION\n”;
cin>>sl;
switch(sl)
{ case 1: cout<<“Enter Element to be inserted”;
cin>>e;
push(stack,top,s,e);
break;
case 2: pop(stack,top);
break;
case 3:disp(stack,top);
break;
case 4: cout<<“ U R X from HERe “;
getch();
exit(0);
break;
default:
cout<<“ Invalid Selection”;
}
cout<<“Do U want 2 continue (y/n)? “;
cin>>ch;
}while(ch==’y’||ch==’Y’);
getch();
} 3)array queue
#include<iostream.h>
#include<conio.h>
#include<process.h>
void insertion(int queue[],int &front,int &rear,int s,int e) \\8)
{ if(rear==s-1)
cout<<“\nOver flow”;
else if(rear==-1)
{ front=rear=0;
queue[rear]=e;
}
else
{ rear++;
queue[rear]=e;
}
}
void deletion(int queue[],int &front,int &rear) //9)
{ if(front==-1)
cout<<“Underflow”;
else
{ cout<<“\nDeleted element is “<<queue[front];
if(front == rear)
front=rear=-1;
else
front++;
}
}
void disp(int queue[],int front,int rear) //10)
{       if(front==-1)
cout<<“\nNothing to display”;
else
{ cout<<“ \n Elements in Queue is :\n”;
for(int i=front;i<=rear;i++)
cout<<queue[i]<<“\t “;
}
}
void main()
{ int queue[50],s=50,front=-1,rear=-1,e;
clrscr();
int sl;
char ch;
do{
clrscr();
cout<<“MENU\n”;
cout<<“ 1. INSERTION\n”;
cout<<“ 2. deletion\n”;
cout<<“3.display\n”;
cout<<“ 4. exIT\n”;
cout<<“eNTER SELECTION\n”;
cin>>sl;
switch(sl)
{ case 1: cout<<“Enter Element to be inserted”;
cin>>e;
insertion(queue,front,rear,s,e);
break;
case 2: deletion(queue,front,rear);
break;
case 3:disp(queue,front,rear);
break;
case 4: cout<<“ U R Xit from HERe “;
getch();
exit(0);
default:
cout<<“ Invalid Selection”;
}
cout<<“\nDo U want 2 continue (y/n)? “;
cin>>ch;
}while(ch==’y’||ch==’Y’);
getch();
} 4)Cqueue
#include<iostream.h>
#include<conio.h>
#include<process.h>
void insertion(int cqueue[],int &front,int &rear,int s,int e) //11)
{ if((front==0 && rear==s-1)||front==rear+1)
cout<<“\nOver flow”;
else
{ if(rear==-1)
front=rear=0;
else if(rear==s-1)
rear=0;
else
rear++;
cqueue[rear]=e;
}

}
void deletion(int cqueue[],int &front,int &rear,int s) //12)
{ if(front==-1)
cout<<“Underflow”;
else
{ cout<<“\nDeleted element is “<<cqueue[front];
if(front == rear)
front=rear=-1;
else if(front==s-1)
front=0;
else
front++;
}
}
void disp(int cqueue[],int front,int rear,int s) //14)
{       int i;
if(front==-1)
cout<<“\nNothing to display”;
else
{ cout<<“ \n Elements in Queue is”;
cout<<“(front as >> and rear as<< and free as - :\n”;
if(rear>=front)
{ for(i=0;i<front;i++)
cout<<“ - “;
cout<<“ >> “;
for(i=front;i<=rear;i++)
cout<<cqueue[i]<<“ <- “;
cout<<“ << “;
}
else
{ for(i=0;i<=rear;i++)
cout<<cqueue[i]<<“ <- “;
cout<<“ << “;
for(i=rear;i<front;i++)
cout<<“ <- “;
cout<<“ >> “;
for(i=front;i<s;i++)
cout<<cqueue[i]<<“ <- “;

}
}
}