Jan

31

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class HtmlDemo1 extends JPanel
implements ActionListener {
JLabel theLabel;
JTextArea htmlTextArea;

public HtmlDemo1() {
setLayout(null);
this.setSize(400,400);
String initialText = “<html>\n” +
“Color and font test:\n” +
“<ul>\n” +
“<li><font color=red>red</font>\n” +
“<li><font color=blue>blue</font>\n” +
“<li><font color=green>green</font>\n” +
“<li><font size=-2>small</font>\n” +
“<li><font size=+2>large</font>\n” +
“<li><i>italic</i>\n” +
“<li><b>bold</b>\n” +
“</ul>\n”;

htmlTextArea = new JTextArea(10, 20);
htmlTextArea.setText(initialText);
theLabel=new JLabel();
theLabel.setText(initialText);
theLabel.setBounds(20,20,200,200);
htmlTextArea.setBounds(250,20,200,200);
add(theLabel);
add(htmlTextArea);
JButton b=new JButton(“Change”);
b.setBounds(20,300,100,30);
add(b);
b.addActionListener(this);

}

public void actionPerformed(ActionEvent e) {
theLabel.setText(htmlTextArea.getText());
}

public static void main(String[] args) {
HtmlDemo1 hd=new HtmlDemo1();
Frame f=new Frame();
f.add(hd);
f.setSize(400,400);
f.setVisible(true);
}
}

Jan

31

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class HtmlDemo extends JPanel
implements ActionListener {
JLabel theLabel;
JTextArea htmlTextArea;

public HtmlDemo() {
setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS));

String initialText = “<html>\n” +
“Color and font test:\n” +
“<ul>\n” +
“<li><font color=red>red</font>\n” +
“<li><font color=blue>blue</font>\n” +
“<li><font color=green>green</font>\n” +
“<li><font size=-2>small</font>\n” +
“<li><font size=+2>large</font>\n” +
“<li><i>italic</i>\n” +
“<li><b>bold</b>\n” +
“</ul>\n”;

htmlTextArea = new JTextArea(10, 20);
htmlTextArea.setText(initialText);
JScrollPane scrollPane = new JScrollPane

(htmlTextArea);

JButton changeTheLabel = new JButton(“Change the

label”);
changeTheLabel.setMnemonic(KeyEvent.VK_C);
changeTheLabel.setAlignmentX

(Component.CENTER_ALIGNMENT);
changeTheLabel.addActionListener(this);

theLabel = new JLabel(initialText) {
public Dimension getPreferredSize() {
return new Dimension(200, 200);
}
public Dimension getMinimumSize() {
return new Dimension(200, 200);
}
public Dimension getMaximumSize() {
return new Dimension(200, 200);
}
};
theLabel.setVerticalAlignment(SwingConstants.CENTER);
theLabel.setHorizontalAlignment

(SwingConstants.CENTER);

JPanel leftPanel = new JPanel();
leftPanel.setLayout(new BoxLayout(leftPanel,

BoxLayout.PAGE_AXIS));
leftPanel.setBorder

(BorderFactory.createCompoundBorder(
BorderFactory.createTitledBorder(
“Edit the HTML, then click the button”),
BorderFactory.createEmptyBorder

(10,10,10,10)));
leftPanel.add(scrollPane);
leftPanel.add(Box.createRigidArea(new Dimension

(0,10)));
leftPanel.add(changeTheLabel);

JPanel rightPanel = new JPanel();
rightPanel.setLayout(new BoxLayout(rightPanel,

BoxLayout.PAGE_AXIS));
rightPanel.setBorder

(BorderFactory.createCompoundBorder(
BorderFactory.createTitledBorder(“A

label with HTML”),
BorderFactory.createEmptyBorder

(10,10,10,10)));
rightPanel.add(theLabel);

setBorder(BorderFactory.createEmptyBorder

(10,10,10,10));
add(leftPanel);
add(Box.createRigidArea(new Dimension(10,0)));
add(rightPanel);
}

//React to the user pushing the Change button.
public void actionPerformed(ActionEvent e) {
theLabel.setText(htmlTextArea.getText());
}

/**
* Create the GUI and show it.  For thread safety,
* this method should be invoked from the
* event dispatch thread.
*/
private static void createAndShowGUI() {
//Create and set up the window.
JFrame frame = new JFrame(“HtmlDemo”);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//Add content to the window.
frame.add(new HtmlDemo());

//Display the window.
frame.pack();
frame.setVisible(true);
}

public static void main(String[] args) {
//Schedule a job for the event dispatch thread:
//creating and showing this application’s GUI.
SwingUtilities.invokeLater(new Runnable() {
public void run() {
//Turn off metal’s use of bold fonts
UIManager.put(“swing.boldMetal”,

Boolean.FALSE);
createAndShowGUI();
}
});
}
}
For more details see this page: http://docs.oracle.com/javase/tutorial/uiswing/components/html.html

Jan

24

#include<stdio.h>

#include<conio.h>

void main(){

int i,k,n;

char name[50][30],temp[30];

clrscr();

printf(“Enter number of persons: “);

scanf(“%d”,&n);

printf(“\n”);

fflush(stdin);

for(i=0;i<n;i++){

printf(“Enter name of person %d: “,i+1);

gets(name[i]);

}

for(k=0;k<n-1;k++){

for(i=0;i<n-k-1;i++){

if(strcmp(name[i],name[i+1])>0){

strcpy(temp,name[i]);

strcpy(name[i],name[i+1]);

strcpy(name[i+1],temp);

}

}

}

printf(“\nSorted list…\n\n”);

for(i=0;i<n;i++)

puts(name[i]);

getch();

}

Jan

24

#include<stdio.h>

#include<conio.h>

#define MAX 3

void main(){

int m,n,i,j;

//int const num=10;

int arr1[MAX][MAX],arr2[MAX][MAX],arr3[MAX][MAX];

printf(“Enter size of matrics as m,n: “);

scanf(“%d%d”,&m,&n);

if (m>MAX || n>MAX){

printf(“\nMatrix sizes are more than”);

printf(“declared sizes\n”);

exit(1);

}

printf(“Enter%d elements of matrix A row-wise as \n”,m*n);

for(i=0;i<m;i++){

for(j=0;j<n;j++){

scanf(“%d”,&arr1[i][j]);

}

}

for(i=0;i<m;i++){

for(j=0;j<n;j++){

scanf(“%d”,&arr2[i][j]);

}

}

for(i=0;i<m;i++){

for(j=0;j<n;j++){

arr3[i][j]=arr1[i][j]+arr2[i][j];

}

}

for(i=0;i<m;i++){

for(j=0;j<n;j++){

printf(“%d “,arr3[i][j]);

//arr2[j][i]=arr1[i][j];

}

printf(“\n”);

}

getch();

}

Jan

24

#include<stdio.h>

#include<conio.h>

#define MAX 3

void main(){

int i,j,k;

int arr1[MAX][MAX],arr2[MAX][MAX],arr3[MAX][MAX];

printf(“Enter%d elements of matrix A row-wise\n”,MAX*MAX);

for(i=0;i<2;i++){

for(j=0;j<2;j++){

scanf(“%d”,&arr1[i][j]);

}

}

for(i=0;i<2;i++){

for(j=0;j<2;j++){

scanf(“%d”,&arr2[i][j]);

}

}

for(i=0;i<2;i++){

for(j=0;j<2;j++){

arr3[i][j]=0;

for(k=0;k<2;k++){

arr3[i][j]+=arr1[i][k] * arr2[k][j];

}

}

}

for(i=0;i<2;i++){

for(j=0;j<2;j++){

printf(“%d “,arr3[i][j]);

//arr2[j][i]=arr1[i][j];

}

printf(“\n”);

}

getch();

}

Jan

24

#include<stdio.h>

#include<conio.h>

#define MAX 3

void main(){

int i,j;

int arr1[MAX][MAX],arr2[MAX][MAX];

printf(“Enter%d elements of matrix A row-wise\n”,MAX*MAX);

for(i=0;i<3;i++){

for(j=0;j<3;j++){

scanf(“%d”,&arr1[i][j]);

}

}

for(i=0;i<3;i++){

for(j=0;j<3;j++){

arr2[j][i]=arr1[i][j];

}

}

for(i=0;i<3;i++){

for(j=0;j<3;j++){

printf(“%d “,arr2[i][j]);

//arr2[j][i]=arr1[i][j];

}

printf(“\n”);

}

getch();

}

Jan

23

#include<stdio.h>

struct node{

int num;

struct node *left;

struct node *right;

};

typedef struct node NODE;

NODE *root=NULL;

NODE *insert(NODE *tree, int num);

void preorder(NODE *tree);

void inorder(NODE *tree);

void postorder(NODE *tree);

int count=1;

void main(){

int choice;

int digit;

clrscr();

do{

printf(“\nEnter 1 : Insert a node in the BT”);

printf(“\nEnter 2 : Display (preorder) the BT”);

printf(“\nEnter 3 : Display (inorder) the BT”);

printf(“\nEnter 4 : Display (postorder) the BT”);

printf(“\nEnter 5 : END\n”);

scanf(“\n %d”,&choice);

switch(choice){

case 1: printf(“Enter ineger: To quit enter 0:: “);

scanf(“%d”,&digit);

while(digit !=0){

root=insert(root,digit);

scanf(“%d”,&digit);

}

break;

case 2: printf(“\n Preorder traversing TREE”);

preorder(root);

break;

case 3: printf(“\n Inorder traversing TREE”);

inorder(root);

break;

case 4: printf(“\n Postorder traversing TREE”);

postorder(root);

break;

case 5: printf(“\n END”);exit(0);

}

}while(choice>=1 && choice<=5);

}

NODE *insert(NODE *p,int digit){

if(p==NULL){

p=(NODE*) malloc(sizeof(NODE));

p->left=p->right=NULL;

p->num=digit;

}

else{

if(digit<=p->num)

p->left=insert(p->left,digit);

else

p->right=insert(p->right,digit);

}

return(p);

}

void preorder(NODE *p){

if(p!=NULL){

printf(“\n%d”,p->num);

preorder(p->left);

preorder(p->right);

}

}

void inorder(NODE *p){

if(p!=NULL){

inorder(p->left);

printf(“\n%d”,p->num);

inorder(p->right);

}

}

void postorder(NODE *p){

if(p!=NULL){

postorder(p->left);

postorder(p->right);

printf(“\n%d”,p->num);

}

}

Jan

23

#include<stdio.h>

#include<conio.h>

#include<malloc.h>

struct node

{

int num;

struct node *next;

struct node *prev;

};

typedef struct node Node;

Node *temp,*start=NULL,*p;

void input();

void output();

void revoutput();

void insert();

void delet();

void main()

{

int choice;

clrscr();

do

{

printf(“\n 1 Creat\n”);

printf(“\n 2 Display\n”);

printf(“\n 3 Rev Display\n”);

printf(“\n 4 Insert\n”);

printf(“\n 5 Delete\n”);

printf(“\n 6 Exit\n”);

printf(“\n please enter your choice:- “);

scanf(“%d”,&choice);

switch(choice)

{

case 1: input();

break;

case 2: output();

break;

case 3: revoutput();

break;

case 4:insert();

break;

case 5:delet();

break;

case 6: exit(0);

}

}while(choice!=6);

getch();

}

void input()

{

temp=(Node*)malloc(sizeof(Node));

printf(“\n Enter a number:-“);

scanf(“%d”,&temp->num);

if(start==NULL)

{

temp->prev=NULL;

start=temp;

temp->next=NULL;

p=temp;

}

else

{

temp->next=NULL;

temp->prev=p;

p->next=temp;

p=temp;

}

}

void output()

{

temp=start;

printf(“\n Value of list\n”);

while(temp!=NULL)

{

printf(“%d\n”,temp->num);

temp=temp->next;

}

}

void revoutput()

{

Node *t,*r;

r=start;

printf(“\n Value in Rev orderlist list\n”);

while(r!=NULL)

{

t=r;

r=r->next;

}

while(t!=NULL)

{

printf(“%d\n”,t->num);

t=t->prev;

}

}

void insert()

{

int i,n;

Node *t;

printf(“\n enter the position where u want to insert:-“);

scanf(“%d”,&n);

temp=start;

p=(Node*)malloc(sizeof(Node));

printf(“\nEnter a new number:-“);

scanf(“%d”,&p->num);

if(n==1)

{

p->prev=NULL;

p->next=temp;

start=p;

temp->prev=p;

}

else

{

for(i=2;i<n;i++)

{

temp=temp->next;

}

p->next=temp->next;

temp->next=p;

p->prev=temp;

p->next->prev=p;

}

}

void delet()

{

int n;

Node *p;

printf(“\n Enter the value u want to delet:-“);

scanf(“%d”,&n);

temp= start;

while(temp!=NULL)

{

if(temp->num==n)

{

if(temp==start)

{

start=temp->next;

start->prev=NULL;

}

else

{

p->next=temp->next;

temp->next->prev=p;

}

free(temp);

break;

}

p=temp;

temp=temp->next;

}

}

Jan

23

#include<stdio.h>

#include<conio.h>

#include<stdlib.h>

struct node

{

int num;

struct node *next;

}*start=NULL;

typedef struct node NODE;

NODE *temp,*p;

void insert();

void display();

void insertend();

void delnode();

void main()

{

int cho,data;

clrscr();

do

{

printf(“\n 1.insert”);

printf(“\n 2.display”);

printf(“\n 3.insertend”);

printf(“\n4.delnode”);

printf(“\n5.exit”);

printf(“\nenter your choice”);

scanf(“%d”,&cho);

switch(cho)

{

case 1:insert();

break;

case 2:display();

break;

case 3:insertend();

break;

case 4:delnode();

break;

case 5:exit(0);

}

}

while(cho!=5);

getch();

}

void insert()

{

temp=(NODE*)malloc(sizeof(NODE));

printf(“enter a no”);

scanf(“%d”,&temp->num);

if(start==NULL)

{

temp->next=NULL;

start=temp;

p=temp;

}

else

{

temp->next=NULL;

p->next=temp;

p=temp;

}

}

void display()

{

NODE *temp;

for(temp=start;temp!=NULL;temp=temp->next)

printf(“\nno=%d,address=%d”,temp->num,temp->next);

}

void insertend()

{

int i,n;

printf(“Enter no that after node is inserted”);

scanf(“%d”,&n);

p=(NODE*)malloc(sizeof(NODE));

printf(“Enter element “);

scanf(“%d”,&p->num);

temp=start;

for(i=1;i<n;i++)

{

temp=temp->next;

}

if(n==0)

{

p->next=temp;

start=p;

}

else

{

p->next=temp->next;

temp->next=p;

}

}

void delnode()

{

NODE *p;

int data;

printf(“Enter element to be delete”);

scanf(“%d”,&data);

temp=start;

p=start;

while(temp!=NULL)

{

if(temp->num==data)

{

if(temp==start)

{

start=temp->next;

}

else

{

p->next=temp->next;

}

free(temp);

break;

}

p=temp;

temp=temp->next;

}

}

Jan

23

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
typedef struct node
{
int n;
struct node *link;
}NODE;
void main()
{
int c;
NODE *temp,*start=NULL,*p;
clrscr();
//temp=(NODE *)malloc(sizeof(NODE));

while(1)
{
printf("\n\t 1. PUSH\n\t 2. POP");
printf("\n\t 3. DISPLAY\n\t 4. EXIT");
printf("\n\t ENTER ANY CHOICE\t");
scanf("%d",&c);
switch(c)
{
case 1: printf("\n\t ENTER ANY NUMBER\t");
temp=(NODE *)malloc(sizeof(NODE));
scanf("%d",&temp->n);
if(start==NULL)
{
temp->link=NULL;
start=temp;
p=temp;
}
else
{
temp->link=NULL;
p->link=temp;
p=temp;
}
break;
case 2: if(start==NULL)
printf("\n\tEMPTY LIST");
else
printf("\n\t %d IS DELETED",start->n);
start=start->link;
break;
case 3: temp=start;
while(temp!=NULL)
{
printf("\n\t\t%d",temp->n);
temp=temp->link;
}
break;
case 4:exit(1);
default:printf("\n\t YOU ENTERED AN INVALID CHOICE");
printf("\n\nPLEASE TRY AGAIN……….\t");

}
}
getch();
}

Jan

23

#include<stdio.h>

#include<malloc.h>

void main(){

struct node

{

int num;

struct node *next;

}*start=NULL;

typedef struct node NODE;

NODE *p, *first=NULL,*temp;

char choice;

clrscr();

do{

p=(NODE*) malloc(sizeof(NODE));

printf(“Enter the data item\n”);

scanf(“%d”,&p->num);

if(first==NULL){

p->next=NULL;

temp=p;

first=p;

}

else{

temp->next=p;

p->next=NULL;

temp=p;

}

printf(“Do you want to continue (type y or n) ?\n”);

fflush(stdin);

scanf(“%c”,&choice);

}while(choice==’y’ || choice==’Y’);

printf(“Status of Link List is ——————–\n”);

temp=first;

while(temp!=NULL){

printf(“%d\n”,temp->num);

temp=temp->next;

}

//printf(“Number of Nodes in the list = %d\n”,count);

getch();

}

Jan

23

#include<stdio.h>
#include<conio.h>
#define maxsize 5
int Q[maxsize];
void main(){
int front=-1,rear=-1;
int item,i;
char ch=’y’;
do{
printf("Enter Item into Q: ");
scanf("%d",&item);
if(rear>=maxsize-1){
printf("\n Queue oveflow");
}
else{
rear=rear+1;
Q[rear]=item;
}
if(front==-1){
front=0;
}
printf("Do u want to continue: ");
fflush(stdin);
scanf("%c",&ch);
}while(ch==’y’||ch==’Y’);
printf("Do u want to delete item from Q: ");
fflush(stdin);
scanf("%c",&ch);
while(ch==’y’){
if(front<0){
printf("Q is Empty ");
}
else{
item=Q[front];
printf("Deleteed item is: %d\n",item);
front=front+1;
}
if(front>rear){
front=rear=-1;
}
printf("Do u want to delete item from Q: ");
fflush(stdin);
scanf("%c",&ch);
}
/*printf("————–DISPLAY VALUES FROM Q——–");
for(i=front;i<=rear;i++){
printf("%d\n",Q[i]);

}*/
}

Jan

23

#include<stdio.h>

#include<conio.h>

#include<malloc.h>

struct node

{

int data;

struct node *link;

};

void push(struct node**, int);

int pop(struct node **);

void traverse(struct node**);

void delstack(struct node**);

void main()

{

struct node *s=NULL;

int i;

clrscr();

push(&s,8);

push(&s,20);

push(&s,-4);

push(&s,15);

push(&s,18);

push(&s,12);

push(&s,16);

push(&s,25);

push(&s,0);

push(&s,10);

push(&s,100);

//traverse(&s);

i=pop(&s);

printf(“\nItem popped: %d”,i);

i=pop(&s);

printf(“\nItem popped: %d”,i);

i=pop(&s);

printf(“\nItem popped: %d”,i);

i=pop(&s);

printf(“\nItem popped: %d”,i);

i=pop(&s);

printf(“\nItem popped: %d”,i);

i=pop(&s);

printf(“\nItem popped: %d”,i);

i=pop(&s);

printf(“\nItem popped: %d”,i);

i=pop(&s);

printf(“\nItem popped: %d”,i);

i=pop(&s);

printf(“\nItem popped: %d”,i);

i=pop(&s);

printf(“\nItem popped: %d”,i);

i=pop(&s);

printf(“\nItem popped: %d\n”,i);

traverse(&s);

delstack(&s);

}

void push(struct node **top,int item){

struct node *temp;

temp=(struct node*) malloc(sizeof(struct node));

if(temp==NULL)

{

printf(“\nStack is full”);

}

temp->data=item;

temp->link=*top;

*top=temp;

}

int pop(struct node **top){

struct node *temp;

int item;

if(*top==NULL){

printf(“\n Stack is empty”);

return NULL;

}

temp=*top;

item=temp->data;

*top=(*top)->link;

free(temp);

return item;

}

void delstack(struct node **top){

struct node *temp;

if(*top==NULL)

return;

while(*top!=NULL){

temp=*top;

*top=(*top)->link;

free(temp);

}

}

void traverse(struct node**top){

struct node *temp;

int item;

if(*top==NULL){

printf(“\n Stack is empty”);

return;

}

while(*top!=NULL){

temp=*top;

item=temp->data;

*top=(*top)->link;

printf(“%d\n”,item);

}

}