Chatbox

Các bạn vui lòng dùng từ ngữ lịch sự và có văn hóa,sử dụng Tiếng Việt có dấu chuẩn. Chúc các bạn vui vẻ!
12/09/2013 18:09 # 1
Sinhvienkhoa17
Cấp độ: 13 - Kỹ năng: 8

Kinh nghiệm: 105/130 (81%)
Kĩ năng: 55/80 (69%)
Ngày gia nhập: 18/09/2011
Bài gởi: 885
Được cảm ơn: 335
Phân tích cấu trúc và giải thuật (Java và C cách sử dụng)


Bài 1:Tính giao thừa 1 số .

ex: 4! =4*3*2*1        Giả sử 4= n       => n!=n*(n-1)*...1;   => n=0 nến 1!=1    

n!=                     | 1 nếu n=0;

                           | n*(n-1)! nếu n>0;

Code C:

#include<stdio.h>

#include<conio.h>

#include<iostream.h>

int giaothuavonglap(int n){

    long kq=1;

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

         kq*=i;    

return kq;

}

int giaothuadequy(int n){

    if(n==0)

    return 1;

     else

    return n*giaothuadequy(n-1);

}

void main(){

clrscr();

int n;

printf("\nnhap n");

scanf("%d",&n);

printf("giao thua la: %d",giaothuadequy);

}

 

Code Java:

package dequy;
import java.util.*;
public class exercise_four {
public int giaothuadequy(int n){
      if(n==0)
               return 1;
       else
                return n*giaothuadequy(n-1);
}
public int giaothuavonglap(int n){
           int kq=1;
          for(int i=1;i<=n;i++)
                   kq*=i;
           return kq;
}
public static void main(String[]args){
     exercise_four reply=new exercise_four();
     Scanner solve=new Scanner(System.in);
     int n;
     System.out.println("nhap n:");
      n=solve.nextInt();
     System.out.println("giao thuaDQ n:"+reply.giaothuadequy(n));
      System.out.println("giao thuaVL n"+reply.giaothuavonglap(n));
}
}

 





 
12/09/2013 18:09 # 2
Sinhvienkhoa17
Cấp độ: 13 - Kỹ năng: 8

Kinh nghiệm: 105/130 (81%)
Kĩ năng: 55/80 (69%)
Ngày gia nhập: 18/09/2011
Bài gởi: 885
Được cảm ơn: 335
Phản hồi: Phân tích cấu trúc và giải thuật (Java và C cách sử dụng)


Bài 2:Tính x^y              x thuộc R,y thuộc N*

Bước 1: soi ! 

4^3=4*4*4;

4^0=1

Đệ quy:

1 nếu y=0;

x* x^(y-1) nếu y>0

Bước 2: Play

Code C:

include<iostream.h>

include<conio.h>

include<stdio.> 

 int mudequy(int x,int y){

    if(y==0)   
           return 1;
    else
            return x*mudequy(x,y-1);
}
 int muvonglap(int x,int y){
     if(y==0)
             return 1;
     else{
             int kq=x;
     while(y>0){
               kq+=x;
                 y--;
}
      return kq;}
}
void main(){
        clrscr();
        int x,y;
        printf("nhap x:");scanf("%d",&x);
        printf("nhap y:");scanf("%d",&y);
        printf("x^y DQ:",mudequy(x,y));
        printf("x^y VL:",muvonglap(x,y));   
        getch();
}

Code Java:

package dequy;

import java.util.*;
public class exercise_four {
public int mudequy(int x,int y){
    if(y==0)   
           return 1;
    else
            return x*mudequy(x,y-1);
}
public int muvonglap(int x,int y){
     if(y==0)
             return 1;
     else{
             int kq=x;
     while(y>0){
               kq+=x;
                 y--;
}
      return kq;}
}
public static void main(String[]args){
exercise_four reply=new exercise_four();
Scanner solve=new Scanner(System.in);
int x,y;
System.out.println("nhap x:");
x=solve.nextInt();
System.out.println("nhap y:");
y=solve.nextInt();
System.out.println("x^y DQ n:"+reply.mudequy(x,y));
System.out.println("x^y VL n:"+reply.muvonglap(x,y));
}
}
 




 
12/09/2013 18:09 # 3
Sinhvienkhoa17
Cấp độ: 13 - Kỹ năng: 8

Kinh nghiệm: 105/130 (81%)
Kĩ năng: 55/80 (69%)
Ngày gia nhập: 18/09/2011
Bài gởi: 885
Được cảm ơn: 335
Phản hồi: Phân tích cấu trúc và giải thuật (Java và C cách sử dụng)


Bài 3 :Chuyển đổi tất cả từ 1 tới 256 mã nhị phân

Code Java:

public class exercise_four{
final int end=256;
public String convert(int n){
     String solve=" ";
     while(n>0)
     {
      solve=n%2+solve;
        n=n/2;
}
        return solve;
}
public String convertDQ(int n){
     String solve=" ";
     if(n>0)
     {
      solve=n%2+solve;
      convertDQ(n/2);
     }
      else
      return solve;
}
public void display(){
       System.out.println("Output Object:");
        for(int i=1;i<=end;i++){
        System.out.println(i+"\t\t"+convert(i));
}
}
public static void main(String[]args){
exercise_four kq=new exercise_four();
kq.display();
}
}
 
...Đang suy nghĩ đệ quy... loadding....xong




 
12/09/2013 20:09 # 4
Sinhvienkhoa17
Cấp độ: 13 - Kỹ năng: 8

Kinh nghiệm: 105/130 (81%)
Kĩ năng: 55/80 (69%)
Ngày gia nhập: 18/09/2011
Bài gởi: 885
Được cảm ơn: 335
Phản hồi: Phân tích cấu trúc và giải thuật (Java và C cách sử dụng)


Bài 4:Danh sách liên kết trong Java

mảng Hình vuông :chiều dài,chiều rộng

mảng hình tam giác:a,b,c;

mảng hình tròn:bán kính

Tìm diện tích lớn nhất ,chu vi lớn nhất của các hình?

public abstract class Shape{
protected String color;
protected int brightness;
public String toString(){
            return "\ncolor"+this.color+"\nbrightness"+this.brightness;
}
public abstract double area();
public abstract double perimeter();
}
 
// lớp mới
public class hinhchunhat extends Shape{
private double dai,rong;
public hinhchunhat(String mau,int dosang,int dai,int rong){
              this.mau=mau;
              this.dosang=dosang;
              this.dai=dai;
              this.rong=rong;
}
public String toString(){
              return super.toString()+"dai:"+this.dai+"rong:"+this.rong+
              "dien tich:"+this.dientich()+"chu vi:"+this.chuvi();
}
public double chuvi(){
             return this.dai*this.rong;
}
public double dientich(){
             return (this.dai+this.rong)*2;
}
 
}
  
//lớp mới
public class hinhtamgiac extends Shape{
private double a,b,c;
public hinhtamgiac(String mau,int dosang,double a,double b,double c){
          this.mau=mau;
          this.dosang=dosang;
          this.a=a;
          this.b=b;
          this.c=c;
}
public String toString(){
           return super.toString()+"a:"+this.a+"b:"+this.b+"c:"+this.c+
         "dien tich"+this.dientich()+"chu vi"+this.chuvi();
}
public double dientich(){
          double p=(this.a+this.b+this.c)/2;
         return Math.sqrt(p*(p-a)*(p-b)*(p-c));
}
public double chuvi(){
         return this.a+this.b+this.c;
}
}
 
//lớp mới
public class hinhtron extends Shape{
private double radius;
final double PI=3.14;
public hinhtron(String mau,int dosang,double radius){
       this.mau=mau;
       this.dosang=dosang;
       this.radius=radius;
}
public String toString(){
       return super.toString()+"mau:"+this.mau+
      "dosang:"+this.dosang+"radius:"+this.radius+
"dien tich"+this.dientich()+"chu vi"+this.chuvi();
}
public double chuvi(){
     return this.radius*this.radius*PI;
}
public double dientich(){
     return this.radius*2*PI;
}
}
 
//lớp mới
public class ShapeList {
private int size=6;
private Shape[] shapes=new Shape[size];
public ShapeList(){
       shapes[0]=new hinhtron("rat",3,3);
        shapes[1]=new hinhtamgiac("la ",3,1,2,3);
       shapes[2]=new hinhchunhat("chan",2,1,2);
        shapes[3]=new hinhtron("do",3,3);
       shapes[4]=new hinhtamgiac("ma ",3,1,2,3);
        shapes[5]=new hinhchunhat(":(",2,1,2);
}
public double chuvilonnhat(){
double temp=shapes[0].chuvi();
   for(int i=1;i<size;i++){
       if(temp<shapes[i].chuvi())
          temp=shapes[i].chuvi();
}
return temp;
}
public Shape dientichnhonhat(){
double temp=shapes[0].dientich();
int minIndex=0;
        for(int i=1;i<size;i++)
             if(temp>shapes[i].dientich()){
                   minIndex=i;
                   temp=shapes[i].dientich();
              }
System.out.println("dien tich nho nhat la:");
System.out.println(shapes[minIndex]);
return shapes[minIndex];
}
public static void main(String[]args){
ShapeList list=new ShapeList();
System.out.println("chu vi lon nhat"+list.chuvilonnhat());
list.dientichnhonhat();
}
 
}
 

Trong C thì chưa nghĩ ra rồi >"< .chắc chào thua





 
12/09/2013 20:09 # 5
Sinhvienkhoa17
Cấp độ: 13 - Kỹ năng: 8

Kinh nghiệm: 105/130 (81%)
Kĩ năng: 55/80 (69%)
Ngày gia nhập: 18/09/2011
Bài gởi: 885
Được cảm ơn: 335
Phản hồi: Phân tích cấu trúc và giải thuật (Java và C cách sử dụng)


Nhưng các bạn đã biết kiểu con trỏ trong C.Nhưng con trỏ lại không vận hành trong Java bù lại Java lại có hàm abstract rất linh động!!!  (nói thẳng chứ Gõ C chán +bùn ngủ với cái  màn hình xanh lè xanh lét)





 
12/09/2013 21:09 # 6
Sinhvienkhoa17
Cấp độ: 13 - Kỹ năng: 8

Kinh nghiệm: 105/130 (81%)
Kĩ năng: 55/80 (69%)
Ngày gia nhập: 18/09/2011
Bài gởi: 885
Được cảm ơn: 335
Phản hồi: Phân tích cấu trúc và giải thuật (Java và C cách sử dụng)


//Nhập xuất mảng .cơ bản mà lại quan trọng nhất ==" .từ cái náy này bạn kết hợp hàm để giải quyết các bài mảng
 
code C:
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void nhap(int A[],int n){
         for(int i=0;i<n;i++)
          scanf("%d",&A[i]);
}
void xuatVL(int A[],int n){
            for(int i=0;i<n;i++)
           printf("%d",A[i]);
}
void xuatdq(int A[],int n){
if(n>0){
           xuatdq(A,n-1);
           printf("%d",A[n-1]);
}
}
void main(){
clrscr();
int A[100],n;
printf("nhap n:");
scanf("%d",&n);
nhap(A,n);
xuatVL(A,n);
xuatdq(A,n);
getch();
}
 
 
code  Java
import java.util;
public class mang(){
private int A[]=new int[100];
private int n; 
void nhap(int n){
         for(int i=0;i<n;i++)
          Sysout(A[i]);       //Sysout + Ctrl + "button cách")
}
void xuatVL(int n){
            for(int i=0;i<n;i++)
          Sysout(A[i]);
}
void xuatdq(int n){
if(n>0){
           xuatdq(A,n-1);
           Sysout(A[n-1]);
}}
public static void main(String[]args){
mang kb=new mang();
Sysout("nhap n:");
int n=kb.nextInt();
kb.nhap(n);
kb.xuatvl(n);
kb.xuatdq(n);
}




 
12/09/2013 22:09 # 7
Sinhvienkhoa17
Cấp độ: 13 - Kỹ năng: 8

Kinh nghiệm: 105/130 (81%)
Kĩ năng: 55/80 (69%)
Ngày gia nhập: 18/09/2011
Bài gởi: 885
Được cảm ơn: 335
Phản hồi: Phân tích cấu trúc và giải thuật (Java và C cách sử dụng)


Phần DSLK trong C

Cấu Trúc của 1 Node


struct tNode
{
     int key;
     tNode *pNext;
};
typedef struct tNode Node;


struct tList
{
     Node *pCaiGi;                                    //Node *pHead;
     Node *pMaGhiKhongDc;                     //Node*pTail;
};
typedef struct tList List;


Khởi tạo Danh sách rỗng


void KhoiTao(List &L)
{
     L.pHead=L.pTail=NULL;
}



Tạo 1 Node


Node *TaoNut(int x)
{
     Node *p;
     p=new Node;
     p->key=x;
     p->pNext=NULL;
     return p;
}    



Nhập Danh sách bằng tay


void NhapDanhSach(List &L)
{
     int n, i, x;
     Node *p;
     p=new Node;
     cout<<"Nhap so phan tu: ";
     cin>>n;
     cout<<"Moi nhap cac phan tu: ";
     cout<<endl;
     for(i=0; i<n; i++)
     {
          cin>>x;
          p=TaoNut(x);
          Insert_First(L, p);
     }
}



Tạo Danh sách ngẫu nhiên


void  NhapDS_Random(List &L)
{
     int  i, n;
     Node *p;
     p=new  Node;
     cout<<"\nNhap Vao So Phan Tu: ";
     cin>>n;
     for(i=0; i<n; i++)
     {
          p=TaoNut(rand()%10-rand()%10);
          Insert_First(L, p);
     }
}



Xuất Danh sách liên kết


 
void XuatDanhSach(List L)
{
     Node *p=L.pHead;
     cout<<"pHead -> ";
     while(p!=NULL)
     {
          cout<<p->key<<" -> ";
          p=p->pNext;
     }
     cout<<"NULL";
}

Thêm 1 Node đầu danh sách


void Insert_First(List &L, Node *p)
{
     if(L.pHead==NULL)
          L.pHead=L.pTail=p;
     else
     {
          p->pNext=L.pHead;
          L.pHead=p;
     }
}




 
12/09/2013 22:09 # 8
Sinhvienkhoa17
Cấp độ: 13 - Kỹ năng: 8

Kinh nghiệm: 105/130 (81%)
Kĩ năng: 55/80 (69%)
Ngày gia nhập: 18/09/2011
Bài gởi: 885
Được cảm ơn: 335
Phản hồi: Phân tích cấu trúc và giải thuật (Java và C cách sử dụng)


//Xuất và nhập NOde ^^" cái ni ni quan trọng lắm đóa 

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
struct Node{
           int Info;
           Node *next;
};
typedef Node*Nodeptr;
void value(Nodeptr &first,int x,Nodeptr p){
if(first==p){
       first=new Node;
       first->Info=x;
       first->next=p;
}
else
        value(first->next,x,p);
}
void TaoDS(Nodeptr&first){
int n,x;
first=NULL;
printf("nhap so phan tu DS>0:");
scanf("%d",&n);
for(int i=1;i<=n;i++){
      printf("phan tu %d:",i);
      scanf("%d",&x);
      value(first,x,NULL);}
}
void xuatDQ(Nodeptr first){
if(first!=NULL){
       printf("%d->",first->Info);
       xuatDQ(first->next);
}
else
       printf("NULL");
}
void xuatVL(Nodeptr first){
Nodeptr q=first;
while(q!=NULL){
       printf("%d->",q->Info);
       q=q->next;
}
printf("NULL");
}
void main(){
Nodeptr L;
clrscr();
TaoDS(L);
xuatDQ(L);
xuatVL(L);
getch();
}




 
Các thành viên đã Thank Sinhvienkhoa17 vì Bài viết có ích:
13/09/2013 12:09 # 9
Sinhvienkhoa17
Cấp độ: 13 - Kỹ năng: 8

Kinh nghiệm: 105/130 (81%)
Kĩ năng: 55/80 (69%)
Ngày gia nhập: 18/09/2011
Bài gởi: 885
Được cảm ơn: 335
Phản hồi: Phân tích cấu trúc và giải thuật (Java và C cách sử dụng)


xuất nhập danh sách liến kết sinhvien ^^"

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
struct hocsinh{
    char hoten[30];
    int ngaysinh;float diem;
};
struct Node{
    int Info;
    Node *next;
};
typedef Node*Nodeptr;
void chen(Nodeptr &first,int x,Nodeptr p){
    if(first==p){
        first=new Node;
        first->Info=x;
        first->next=p;
    }
    else    
        chen(first->next,x,p);
}
void taods(Nodeptr &first){
    int n;
    hocsinh x;
    first=NULL;
    printf("nhap so phan tu:");
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        printf("\n Hoc sinh",i);
        printf("nhap ho ten:");
        scanf("%30s",&x.hoten);
        printf("nam sinh:");
        scanf("%d",&x.ngaysinh);
        printf("diem:");
        scanf("%f",&x.diem);
    chen(first,x,NULL);
}}
void xuatdl(Nodeptr first){
    Nodeptr q=first;
    printf("hoc sinh:");
    while("NULL"){
        printf("%d",q->Info hoten,q->Info namsinh,q->Info diem);
        q=q->next;
            }
        
}





 
13/09/2013 15:09 # 10
vnttqb
Cấp độ: 13 - Kỹ năng: 8

Kinh nghiệm: 5/130 (4%)
Kĩ năng: 39/80 (49%)
Ngày gia nhập: 21/03/2011
Bài gởi: 785
Được cảm ơn: 319
Phản hồi: Phân tích cấu trúc và giải thuật (Java và C cách sử dụng)


Góp vui đảo ngược một dslk bằng đệ quy và vòng lặp. 

 

#include "stdio.h"
#include "conio.h"
#include "input.cpp"
#include <iostream>
using namespace std;
 
void daonguoc(node *&f)
{
  node *tr=NULL;
  node *su=NULL;
 
 while(f->link!=NULL)
   {
      tr=f;
      f=f->link;
      tr->link=su;
      su=tr;    
    }
    f->link=su;
}
 
void daodq(node *&f,node *&tr)
{
     if(f->link==NULL) { f->link=tr; return;}
    else 
    {
         tr=f;
         f=f->link;
      daodq(f,tr);  
       }
      f->link=tr;
    }
int sum(node *f)
{
     if(f==NULL) return (0);
     else return(f->in +sum(f->link));
}
int xoa(node *&f,node *p){}
int main()
{
    node *f,*l;
    f=NULL;    l=NULL;
    inputds(f,l);  xuat(f);
  //  printf("\nTRUNG BINH CONG CAC SO CHAN TRONG DS LA %f",TBC(f));
 // if(dstangdan(f)==1) printf("\n DANH SACH TANG DAN "); else printf("\n DS KHONG TANG DAN");
 // if(dsdoixung(f,l)) printf("\n DANH SACH DOI XUNG "); else printf("\n DS KHONG DOI XUNG");
//if(dsdoixung(f)) printf("\nDs doi xung"); else printf("\nDS KHONG DOI XUNG");
l=NULL;
daodq(f,l);
 
 xuat(f);
    printf("\nTHE END");
    getch();
}
 
 
 
 
 


======================================================================================================

Cuộc đời là một dòng sông. Ai không bơi thì chết. 
 

Name: Tien (Tory) TRAN
Email: TranTien29@gmail.com


 
Các thành viên đã Thank vnttqb vì Bài viết có ích:
13/09/2013 15:09 # 11
vnttqb
Cấp độ: 13 - Kỹ năng: 8

Kinh nghiệm: 5/130 (4%)
Kĩ năng: 39/80 (49%)
Ngày gia nhập: 21/03/2011
Bài gởi: 785
Được cảm ơn: 319
Phản hồi: Phân tích cấu trúc và giải thuật (Java và C cách sử dụng)


bài tập cho danh sách liên kết lưu thông tin sinh viên và một số bài tập xữ lí 

 

#include "stdio.h"
#include "conio.h"
#include "string.h"
 
/*
Bài 5. H? tên.  N?m sinh gi?i tính. ?i?m trung bình
 
- S?p x?p gi?m theo ?i?m
- Xu?t danh sách theo v? th?
*/
 
struct sv
{
    char hten[40];
    int ns;
    int sex; // 1 la nam - 2 la nu
    float diem;
};
struct node
{
    sv x;
    node *link;
};
/*
void insert(node *&f,node *p,int i)
{
     node *q=new node;
     printf("\n\t Nhap thong tin sv %d",i);
     printf("\n\t\t Ho & Ten : \t"); scanf("%s",&q->x.hten);
     printf("\n\t\t Nam sinh : \t"); scanf("%d",&q->x.ns);
     printf("\n\t\t Gioi tinh [1] Nam || [2] Nu : \t"); scanf("%d",&q->x.sex);
     printf("\n\t\t Diem TB  : \t"); scanf("%f",&q->x.diem);
     q->link=NULL;
     if(f==p) f=q;
     else 
     {
          node *r=f;
         while(r->link!=p) r=r->link;
         r->link=q;
         q->link=p;
         }
         
}*/
void insert(node *&f,node *p,sv a)
{
    node *q=new node;
    /*strcpy(q->x.hten,x.hten);
    q->x.ns=x.ns;
     q->x.sex=x.sex;
    q->x.diem=x.diem;*/
    q->x = a;
     q->link=p;
     if(f==p) f=q;
     else 
     {
          node *r=f;
         while(r->link!=p) r=r->link;
         r->link=q;         
         }
         
}
void taods(node *&f)
{
     FILE *fi;
     fi=fopen("a.txt","rt");
     if(fi==NULL) return;
    sv x;
    int i=0;
   while(feof(fi)==0)
   {  //  fflush(fi);  
    fgets(x.hten,40,fi);
    if(strcmp(x.hten,"")!=0){
    fscanf(fi,"%d",&x.ns);
    i++;
    fscanf(fi,"%d",&x.sex);
    fscanf(fi,"%f",&x.diem);
printf("\n i=%d %s\t\t %d \t\t %d \t\t\t %f",i, x.hten,x.ns,x.sex,x.diem);}
//fscanf(fi,"%s");
    //insert(f,NULL,x);    
 // std::flush();    
     }
 fclose(fi); 
    
}
void inds(node *f)
{
     printf("\n Ho & Ten : \t");
     printf(" Nam sinh : \t"); 
     printf("[1]Nam [2]Nu : \t");
     printf("Diem TB"); 
     while(f!=NULL)
     {        
         printf("\n %s\t\t %d \t\t %d \t\t\t %f",f->x.hten,f->x.ns,f->x.sex,f->x.diem);
          f=f->link;
          }
}    
void diemtb(node *f)
{
     float diem=0;
     int so=0;
     if(f==NULL) { printf("\n KHONG CO SV NAO"); return ; }
     else
     while(f!=NULL)
     {
     diem=diem+f->x.diem;
     so++;
     f=f->link;
     }
printf("\n Diem trung binh cua %d sv la %f",so,diem/(float) so);
}
void sort(node *f)     
{
     
     while(f!=NULL)
     {
                   node *fi=f;
                   while(fi!=NULL)
                   {
                                  if(fi->x.diem < f->x.diem)
                                  {
                                  sv a=f->x;
                                  f->x=fi->x;
                                  fi->x=a;
                                  }
                   fi=fi->link;
                                  }
                   f=f->link;
                   }
 }
void vithu(node *f)
{
     int v=1;
     int k=1;
     node *q=f;
     while (f!=NULL)
     {
           if(f->x.diem != q->x.diem)
           {
                        printf("\n%s -- %f --- vi thu %d",f->x.hten,f->x.diem,k);
                        v=k;
                       q=f;
                        }
           else
           {
           printf("\n%s -- %f --- vi thu %d",f->x.hten,f->x.diem,v);
           }
          k++;
          f=f->link;
     }
}
           
int main()
{
    node *f=NULL;
    taods(f);
   // inds(f);
   // diemtb(f);
 //  sort(f);
   
   //inds(f);
   //vithu(f);
    getch();
}
     


======================================================================================================

Cuộc đời là một dòng sông. Ai không bơi thì chết. 
 

Name: Tien (Tory) TRAN
Email: TranTien29@gmail.com


 
Các thành viên đã Thank vnttqb vì Bài viết có ích:
26/09/2013 08:09 # 12
Sinhvienkhoa17
Cấp độ: 13 - Kỹ năng: 8

Kinh nghiệm: 105/130 (81%)
Kĩ năng: 55/80 (69%)
Ngày gia nhập: 18/09/2011
Bài gởi: 885
Được cảm ơn: 335
Phản hồi: Phân tích cấu trúc và giải thuật (Java và C cách sử dụng)


Trích:

Bài 3 :Chuyển đổi tất cả từ 1 tới 256 mã nhị phân

Code Java:

public class exercise_four{
final int end=256;
public String convert(int n){
     String solve=" ";
     while(n>0)
     {
      solve=n%2+solve;
        n=n/2;
}
        return solve;
}
public String convertDQ(int n){
     String solve=" ";
     if(n>0)
     {
      solve=n%2+solve;
      convertDQ(n/2);
     }
      else
      return solve;
}
public void display(){
       System.out.println("Output Object:");
        for(int i=1;i<=end;i++){
        System.out.println(i+"\t\t"+convert(i));
}
}
public static void main(String[]args){
exercise_four kq=new exercise_four();
kq.display();
}
}
 
...Đang suy nghĩ đệ quy... loadding....xong
Note: Sau khi làm vài bài đệ quy với vòng lặp mình đã làm phép so sánh và cho thấy
Cách có thể chuyển từ để quy sang vòng lặp nhanh gọn (maybe thôi nhé mình ko dám chắc).Mình luôn hương tới đơn giản hóa thôi
 
 
 
Dựa trên bài trên:điều kiện là sử dụng hàm while not for đó nghe
ng lặp                --Transport->                 Đệ Quy
 
while                                                                   if
n/=2                                                                    title hàm(n/2)
 
bạn hãy thử dụng cách trên làm cho tất cả các bài bạn đã học .kể luôn cả liên kết đơn
Khuyên cáo:không phải tất cả !!! 




 
26/09/2013 09:09 # 13
Sinhvienkhoa17
Cấp độ: 13 - Kỹ năng: 8

Kinh nghiệm: 105/130 (81%)
Kĩ năng: 55/80 (69%)
Ngày gia nhập: 18/09/2011
Bài gởi: 885
Được cảm ơn: 335
Phản hồi: Phân tích cấu trúc và giải thuật (Java và C cách sử dụng)


Hàm Quicksort :sắp xếp dãy tăng dần (bài giải bài thi đề học phần 2012)

void Quicksort(int A[],int L,int R){

                if(L<R){

                int pos=Partition(A,L,R);

                Quicksort(A,L,pos-1);

                Quicksort(A,pos+1,L);  

                }}

int Portition(int A[],int low,int height){

                   int x,lastsmall;

                   x=A[low];

                   lastsmall=low;

                  int i=low+1; 

                   while(i<=height){

                          if(A[i]<x){

                                     lastsmall++;

                                     Hoanvi(A[i],A[lastsmall);}i++;}

                        Hoanvi(A[low],A[lastsmall]);

                       return lastsmall;               

}

void Hoanvi(int a,int b){

int c;c=a;a=b;b=c;

}





 
28/09/2013 20:09 # 14
Sinhvienkhoa17
Cấp độ: 13 - Kỹ năng: 8

Kinh nghiệm: 105/130 (81%)
Kĩ năng: 55/80 (69%)
Ngày gia nhập: 18/09/2011
Bài gởi: 885
Được cảm ơn: 335
Phản hồi: Phân tích cấu trúc và giải thuật (Java và C cách sử dụng)


Model Tree:

mẹo duyệt cây :d ..Yêu cầu: bạn chỉ cần 1 cây thước .hy vọng nó sẽ hữu ích..

Duyệt LNR: (Trái sang phải)

 

 

 

RNL thì tương tự theo chiều ngược lại nha !!!!

Giờ Là duyệt LRN( Trái phải giữa)

 





 
28/09/2013 20:09 # 15
Sinhvienkhoa17
Cấp độ: 13 - Kỹ năng: 8

Kinh nghiệm: 105/130 (81%)
Kĩ năng: 55/80 (69%)
Ngày gia nhập: 18/09/2011
Bài gởi: 885
Được cảm ơn: 335
Phản hồi: Phân tích cấu trúc và giải thuật (Java và C cách sử dụng)


Dựa cái cây ở trên viết dãy thuật:

#define N NULL;

struct Tree{

           int Info;Tree *left,*right;

};

typedef Tree*Treeptr;

Treeptr Tao(int x,Treeptr L,Treeptr R){

              Treeptr a=new Tree;

              a->Info=x;

              a->left=L;

              a->right=R;

              return a;

}

void TaoCay(Treeptr &T){

              Treeptr p,q,r,k,s;

              p=Tao(13,Tao(12,N,N),Tao(19,N,N));

              q=Tao(15,N,p);

               r=Tao(6,Tao(7,N,N),Tao(8,N,N));

               k=Tao(18,r,N);

               s=Tao(20,Tao(25,N,N),k);

               T=Tao(10,q,s);

}

void F(Treeptr T){

                if(T!=NULL){

                F(T->left);

                              printf("%d",T->Info);

                F(T->right);

                }

}

int TongChan(Treeptr T){

               if(T==NULL)

                            return 0;

              else

                           if(T->Info%2==0)

                                        return T->Info+TongChan(T->left)+TongChan(T->right);

                            else

                                         return TongChan(T->left)+TongChan(T->right);

}

void main(){

               clrscr();

               Treeptr L;

               TaoCay(L);

               F(L);

                printf("Tong chan %d",TongChan(L));            

getch();

 

}





 
01/10/2013 21:10 # 16
Sinhvienkhoa17
Cấp độ: 13 - Kỹ năng: 8

Kinh nghiệm: 105/130 (81%)
Kĩ năng: 55/80 (69%)
Ngày gia nhập: 18/09/2011
Bài gởi: 885
Được cảm ơn: 335
Phản hồi: Phân tích cấu trúc và giải thuật (Java và C cách sử dụng)


http://vovanhai.files.wordpress.com/2011/09/c6_stack_queue.pdf

 

Tài liệu về Queue ..hy vọng hữu ích





 
Copyright© Đại học Duy Tân 2010 - 2024