DNA:
import java.util.*;
import java.io.*;
public class DNADescending
{
public static void main(String args[])throws IOException
{
final String dnaFileName="Dnasequence.txt";
final String outputFile="Dnaout.txt";
DNADescending dnaTest=new DNADescending();
try
{
File f=new File(outputFile);
BufferedOutputStream OutputStream=new BufferedOutputStream(new FileOutputStream(f));
PrintWriter pw=new PrintWriter(OutputStream);
dnaTest.readFileAsString(dnaFileName,pw);
pw.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
private void readFileAsString(String filePath,PrintWriter pw)throws java.io.IOException
{
BufferedReader reader=new BufferedReader(new InputStreamReader
(this.getClass().getClassLoader().getResourceAsStream(filePath)));
String strLine;
int count,i,j,temp;
boolean flag;
String[][] line=new String[15][6];
while((strLine=reader.readLine())!=null)
{
String[] word=strLine.split(" ");
count=0;
flag=false;
for(i=0;i<word.length;i++)
{
if(word[i].contains("TATA"))
{
count++;
flag=true;
}
}
if(flag)
{
for(int k=0;k<6;k++)
{
if(line[count][k]==null)
{
line[count][k]=strLine;
System.out.println(line[count][k]);
break;
}
}
}
}
for(i=4;i>0;i--)
for(j=5;j>=0;j--)
{
if(line[i][j]!=null)
writeIntoFile(line[i][j],pw);
}
}
private void writeIntoFile(String str,PrintWriter pw)
{
try
{
pw.println(str);
System.out.println("THE DNA PATTERN HAS BEEN WRITTEN");
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
}
LINKED LIST:
import java.util.*;
interface Stack {
void push(int num);
void pop();
void display();
}
class Arraystack implements Stack {
int[] as;
int top;
int size;
public Arraystack(int n)
{
as = new int[n];
top=-1;
size=n;
}
public void push(int num)
{
if(top<size-1)
{
top++;
as[top]=num;
System.out.println("Element PUSHED successfully...");
}
else
System.out.println("Stack Overflow!!");
}
public void pop()
{
if(top==-1)
System.out.println("Stack Underflow!!...");
else
{
top--;
System.out.println("Element POPPED successfully...");
}
}
public void display()
{
if(top==-1)
System.out.println("...Stack Empty...");
else
{
System.out.println("The contents of stack is...");
int i=top;
while(i>-1)
{
System.out.println(as[i]);
i--;
}
}
}
}
class Liststack implements Stack {
LinkedList ls;
public Liststack()
{
ls = new LinkedList();
}
public void push(int num)
{
ls.addFirst(new Integer(num));
System.out.println("Element PUSHED successfully...");
}
public void pop()
{
if(ls.isEmpty()==true)
System.out.println("Stack Underflow!!...");
else
{
ls.remove();
System.out.println("Element POPPED successfully...");
}
}
public void display()
{
if(ls.isEmpty()==true)
System.out.println("...Stack Empty...");
else
System.out.println("The contents of stack is...\n"+ls);
}
}
class StackTrial {
public static void main(String args[])
{
int s,opt,ch=1;
Scanner inp = new Scanner(System.in);
System.out.println("Enter the size of the stack...");
Arraystack aob = new Arraystack(inp.nextInt());
Liststack lob = new Liststack();
System.out.println("...ARRAY IMPLEMENTATION OF STACK...");
do
{
System.out.println("\n1.Push.\n2.Pop.\n3.Display.\n4.Exit");
opt=inp.nextInt();
if(opt<1 || opt>3)
break;
switch(opt)
{
case 1:
System.out.println("Enter the element to be inserted...");
aob.push(inp.nextInt());
break;
case 2:
aob.pop();
break;
case 3:
aob.display();
break;
}
}while(ch==1);
System.out.println("...LINKED LIST IMPLEMENTATION OF STACK...");
do
{
System.out.println("\n1.Push.\n2.Pop.\n3.Display.\n4.Exit");
opt=inp.nextInt();
if(opt<1 || opt>3)
break;
switch(opt)
{
case 1:
System.out.println("Enter the element to be inserted...");
lob.push(inp.nextInt());
break;
case 2:
lob.pop();
break;
case 3:
lob.display();
break;
}
}while(ch==1);
}
}
No comments:
Post a Comment