Search Results

Search found 148 results on 6 pages for 'davit siradeghyan'.

Page 3/6 | < Previous Page | 1 2 3 4 5 6  | Next Page >

  • question about qsort in c++

    - by davit-datuashvili
    i have following code in c++ #include <iostream> using namespace std; void qsort5(int a[],int n){ int i; int j; if (n<=1) return; for (i=1;i<n;i++) j=0; if (a[i]<a[0]) swap(++j,i,a); swap(0,j,a); qsort5(a,j); qsort(a+j+1,n-j-1); } int main() { return 0; } void swap(int i,int j,int a[]) { int t=a[i]; a[i]=a[j]; a[j]=t; } i have problem 1>c:\users\dato\documents\visual studio 2008\projects\qsort5\qsort5\qsort5.cpp(13) : error C2780: 'void std::swap(std::basic_string<_Elem,_Traits,_Alloc> &,std::basic_string<_Elem,_Traits,_Alloc> &)' : expects 2 arguments - 3 provided 1> c:\program files\microsoft visual studio 9.0\vc\include\xstring(2203) : see declaration of 'std::swap' 1>c:\users\dato\documents\visual studio 2008\projects\qsort5\qsort5\qsort5.cpp(13) : error C2780: 'void std::swap(std::pair<_Ty1,_Ty2> &,std::pair<_Ty1,_Ty2> &)' : expects 2 arguments - 3 provided 1> c:\program files\microsoft visual studio 9.0\vc\include\utility(76) : see declaration of 'std::swap' 1>c:\users\dato\documents\visual studio 2008\projects\qsort5\qsort5\qsort5.cpp(13) : error C2780: 'void std::swap(_Ty &,_Ty &)' : expects 2 arguments - 3 provided 1> c:\program files\microsoft visual studio 9.0\vc\include\utility(16) : see declaration of 'std::swap' 1>c:\users\dato\documents\visual studio 2008\projects\qsort5\qsort5\qsort5.cpp(14) : error C2780: 'void std::swap(std::basic_string<_Elem,_Traits,_Alloc> &,std::basic_string<_Elem,_Traits,_Alloc> &)' : expects 2 arguments - 3 provided 1> c:\program files\microsoft visual studio 9.0\vc\include\xstring(2203) : see declaration of 'std::swap' 1>c:\users\dato\documents\visual studio 2008\projects\qsort5\qsort5\qsort5.cpp(14) : error C2780: 'void std::swap(std::pair<_Ty1,_Ty2> &,std::pair<_Ty1,_Ty2> &)' : expects 2 arguments - 3 provided 1> c:\program files\microsoft visual studio 9.0\vc\include\utility(76) : see declaration of 'std::swap' 1>c:\users\dato\documents\visual studio 2008\projects\qsort5\qsort5\qsort5.cpp(14) : error C2780: 'void std::swap(_Ty &,_Ty &)' : expects 2 arguments - 3 provided 1> c:\program files\microsoft visual studio 9.0\vc\include\utility(16) : see declaration of 'std::swap' 1>c:\users\dato\documents\visual studio 2008\projects\qsort5\qsort5\qsort5.cpp(16) : error C2661: 'qsort' : no overloaded function takes 2 arguments 1>Build log was saved at "file://c:\Users\dato\Documents\Visual Studio 2008\Projects\qsort5\qsort5\Debug\BuildLog.htm" please help

    Read the article

  • longest common subsequence

    - by davit-datuashvili
    i have following code public class LCS1 { public static String lcs(String a,String b) { String x; String y; int alen=a.length(); int blen=b.length(); if (alen==0 || blen==0) { return ""; } else if (a.charAt(alen-1)==b.charAt(blen-1)) { return lcs(a.substring(0,alen-1),b.substring(0,blen-1)); } else { x=lcs(a,b.substring(0,blen-1)); y=lcs(a.substring(0,alen-1),b); } return (x.length()>y.length()) ? x : y; } public static void main(String[]args){ String a="computer"; String b="houseboat"; System.out.println(lcs(a,b)); } } it should return "out" but returns nothing what is problem?

    Read the article

  • question about counting sort

    - by davit-datuashvili
    hi i have write following code which prints elements in sorted order only one big problem is that it use two additional array here is my code public class occurance{ public static final int n=5; public static void main(String[]args){ // n is maximum possible value what it should be in array suppose n=5 then array may be int a[]=new int[]{3,4,4,2,1,3,5};// as u see all elements are less or equal to n //create array a.length*n int b[]=new int[a.length*n]; int c[]=new int[b.length]; for (int i=0;i<b.length;i++){ b[i]=0; c[i]=0; } for (int i=0;i<a.length;i++){ if (b[a[i]]==1){ c[a[i]]=1; } else{ b[a[i]]=1; } } for (int i=0;i<b.length;i++){ if (b[i]==1) { System.out.println(i); } if (c[i]==1){ System.out.println(i); } } } } // 1 2 3 3 4 4 5 1.i have two question what is complexity of this algorithm?i mean running time 2. how put this elements into other array with sorted order? thanks

    Read the article

  • search algorithm using sentinel

    - by davit-datuashvili
    i am trying to do search algorithm using sentinel which reduce time to 3.87n nanoseconds for example compare to this code int search (int t ){ for (int i=0;i<n;i++) if (x[i]==t) return i; return -1; } it takes 4.06 nanoseconds so i am trying to optimize it here is code public class Search{ public static int search(int a[],int t){ int i; int p=0; int n=a.length; int hold; hold=a[n-1]; a[n-1]=t; for ( i=0;;i++) if (a[i]==t) break; a[n-1]=t; if (i==n){ p= -1; } else{ p= i; } return p; } public static void main(String[]args){ int t=-1; int a[]=new int[]{4,5,2,6,8,7,9}; System.out.println(search(a,t)); } } but is show me that 9 is at position 6 which is correct but if t =1 or something else which is not array it show me position 6 too please help

    Read the article

  • question about linux

    - by davit-datuashvili
    i have following question i am writting programs in linux like this from command line i do following steps touch project.java nano project.java and // code here i have questions how can i create new classes interfaces and so on?because in IDE like netbeans i can do click on projects name with right size of mouse choose create new class or interfaces and it is created but how do it in linux if i dont use IDE?

    Read the article

  • help implementing algorithm

    - by davit-datuashvili
    http://en.wikipedia.org/wiki/All_nearest_smaller_values this is site of the problem and here is my code but i have some trouble to implement it import java.util.*; public class stack{ public static void main(String[]args){ int x[]=new int[]{ 0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15 }; Stack<Integer> st=new Stack<Integer>(); for (int a:x){ while (!st.empty() && st.pop()>=a){ System.out.println( st.pop()); if (st.empty()){ break; } else{ st.push(a); } } } } } and here is pseudo code from site S = new empty stack data structure for x in the input sequence: while S is nonempty and the top element of S is greater than or equal to x: pop S if S is empty: x has no preceding smaller value else: the nearest smaller value to x is the top element of S push x onto S

    Read the article

  • maximum of given function

    - by davit-datuashvili
    first of all i am doing programs in java language this code is merely taken from web site i have not question about divide and conqurer but about function and it's argument here is code of ternary search def ternarySearch(f, left, right, absolutePrecision): #left and right are the current bounds; the maximum is between them if (right - left) < absolutePrecision: return (left + right)/2 leftThird = (2*left + right)/3 rightThird = (left + 2*right)/3 if f(leftThird) < f(rightThird): return ternarySearch(f, leftThird, right, absolutePrecision) return ternarySearch(f, left, rightThird, absolutePrecision) i am not asking once again how implement it in java i am asking for example how define function?for example let y=x^+3 yes we can determine it as public static int y(int x){ return x*x+3; } but here return ternarySearch(f, leftThird, right, absolutePrecision) function f does not have argument and how do such?please help me

    Read the article

  • deteminant of matrix

    - by davit-datuashvili
    suppose there is given two dimensional array int a[][]=new int[4][4]; i am trying to find determinant of matrices please help i know how find it mathematical but i am trying to find it in programaticaly

    Read the article

  • Question about my sorting algorithm in C++

    - by davit-datuashvili
    i have following code in c++ #include <iostream> using namespace std; void qsort5(int a[],int n){ int i; int j; if (n<=1) return; for (i=1;i<n;i++) j=0; if (a[i]<a[0]) swap(++j,i,a); swap(0,j,a); qsort5(a,j); qsort(a+j+1,n-j-1); } int main() { return 0; } void swap(int i,int j,int a[]) { int t=a[i]; a[i]=a[j]; a[j]=t; } i have problem 1>c:\users\dato\documents\visual studio 2008\projects\qsort5\qsort5\qsort5.cpp(13) : error C2780: 'void std::swap(std::basic_string<_Elem,_Traits,_Alloc> &,std::basic_string<_Elem,_Traits,_Alloc> &)' : expects 2 arguments - 3 provided 1> c:\program files\microsoft visual studio 9.0\vc\include\xstring(2203) : see declaration of 'std::swap' 1>c:\users\dato\documents\visual studio 2008\projects\qsort5\qsort5\qsort5.cpp(13) : error C2780: 'void std::swap(std::pair<_Ty1,_Ty2> &,std::pair<_Ty1,_Ty2> &)' : expects 2 arguments - 3 provided 1> c:\program files\microsoft visual studio 9.0\vc\include\utility(76) : see declaration of 'std::swap' 1>c:\users\dato\documents\visual studio 2008\projects\qsort5\qsort5\qsort5.cpp(13) : error C2780: 'void std::swap(_Ty &,_Ty &)' : expects 2 arguments - 3 provided 1> c:\program files\microsoft visual studio 9.0\vc\include\utility(16) : see declaration of 'std::swap' 1>c:\users\dato\documents\visual studio 2008\projects\qsort5\qsort5\qsort5.cpp(14) : error C2780: 'void std::swap(std::basic_string<_Elem,_Traits,_Alloc> &,std::basic_string<_Elem,_Traits,_Alloc> &)' : expects 2 arguments - 3 provided 1> c:\program files\microsoft visual studio 9.0\vc\include\xstring(2203) : see declaration of 'std::swap' 1>c:\users\dato\documents\visual studio 2008\projects\qsort5\qsort5\qsort5.cpp(14) : error C2780: 'void std::swap(std::pair<_Ty1,_Ty2> &,std::pair<_Ty1,_Ty2> &)' : expects 2 arguments - 3 provided 1> c:\program files\microsoft visual studio 9.0\vc\include\utility(76) : see declaration of 'std::swap' 1>c:\users\dato\documents\visual studio 2008\projects\qsort5\qsort5\qsort5.cpp(14) : error C2780: 'void std::swap(_Ty &,_Ty &)' : expects 2 arguments - 3 provided 1> c:\program files\microsoft visual studio 9.0\vc\include\utility(16) : see declaration of 'std::swap' 1>c:\users\dato\documents\visual studio 2008\projects\qsort5\qsort5\qsort5.cpp(16) : error C2661: 'qsort' : no overloaded function takes 2 arguments 1>Build log was saved at "file://c:\Users\dato\Documents\Visual Studio 2008\Projects\qsort5\qsort5\Debug\BuildLog.htm" please help

    Read the article

  • delete item from array in java

    - by davit-datuashvili
    hello can anybody tell me what is wrong here? i want delete item from array but it shows me error ArrayIndexOutBound exception public class delete{ public static void main(String[]args){ int i; //delete item from array int k[]=new int[]{77,99,44,11,00,55,66,33,10}; //delete 55 int searchkey=55; int nums=k.length; for ( i=0;i<nums;i++) if (k[i]==searchkey) break; for (int t=i;t<nums;t++) k[t]=k[t+1]; nums--; for (int m=0;m<nums;m++){ System.out.println(k[m]); } } }

    Read the article

  • permutation of array

    - by davit-datuashvili
    for example i have array int a[]=new int[]{3,4,6,2,1}; I need list of all permutation such that if one is like this, {3,2,1,4,6}, others must not be the same i know that if length of array=n then there is n! possible combination please help me to write this algortihm what to do?

    Read the article

  • question about missing element in array

    - by davit-datuashvili
    i have following problem from book introduction algorithm second edition by MIT university problem is following An array A[1 . . n] contains all the integers from 0 to n except one. It would be easy to determine the missing integer in O(n) time by using an auxiliary array B[0 . . n] to record which numbers appear in A. In this problem, however, we cannot access an entire integer in A with a single operation. The elements of A are represented in binary, and the only operation we can use to access them is “fetch the j th bit of A[i],” which takes constant time. Show that if we use only this operation, we can still determine the missing inte- ger in O(n) time please help

    Read the article

  • help implementing All Nearest Smaller Values algorithm

    - by davit-datuashvili
    http://en.wikipedia.org/wiki/All_nearest_smaller_values this is site of the problem and here is my code but i have some trouble to implement it import java.util.*; public class stack{ public static void main(String[]args){ int x[]=new int[]{ 0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15 }; Stack<Integer> st=new Stack<Integer>(); for (int a:x){ while (!st.empty() && st.pop()>=a){ System.out.println( st.pop()); if (st.empty()){ break; } else{ st.push(a); } } } } } and here is pseudo code from site S = new empty stack data structure for x in the input sequence: while S is nonempty and the top element of S is greater than or equal to x: pop S if S is empty: x has no preceding smaller value else: the nearest smaller value to x is the top element of S push x onto S

    Read the article

  • bit count in array

    - by davit-datuashvili
    hello i have following question i know that to count number of set bit in number of number of 1 bit there is following code int t ;//in which we want count how many bit are set for instance 3 011 there is 2 bit set int count=0; while(t>0){ t&=(t-1); count++; } now let take array example int x[]={3,5,6,8,9,7}; i have following code int sum=0; int count; for (int i=0;i<x.length;i++){ count=0; while (x[i]>0){ x[i]&=(x[i]-1); count++; } sum+=count; } I have question what is wrong? it doesn't work doesn't show me result;

    Read the article

  • Looking for advice on how to do some bit-twiddling [closed]

    - by davit-datuashvili
    hi everybody fisrt of all this is not homework and now question is like this suppose i have array int a[]=new int[]{0xBCDA,0xABFE,0xBCAD,0xEFCA,0xFFCA} i know that there is always some hexadecimal number which occurs in all number or in this case A is repeat in array everywhere so my aim is print only repeat number and other numbers should be zero so my new array should be like this 0x000A, 0xA000,0x00A0 0x000A,0x000A any idea please help me? p.s please nobody say that this is homework

    Read the article

  • Heap property of this array

    - by davit-datuashvili
    From programming pearls, it is known that array[1...n] has heap property if for all 2<=i<=n x[i/2]<=x[i]. Here is my code: import java.math.*; public class Heap { public static void main(String[]args){ int x[]=new int[]{12,20,15,29,23,17,22,35,40,26,51,19}; int i=1; while (i<x.length) { if (x[Math.round(i/2)]<=x[i]) System.out.println("heap"); i++; } System.out.println("not heap"); } } Here I used Math.round because 4/2 and 5/2 is same and =2. When I compile this code it shows me at last line that it is not heap. Maybe because the index starts from 1 and we don't pay attention to index 0, yes?

    Read the article

  • select i th smallest element from array

    - by davit-datuashvili
    i have divide and conqurer method to find i th smalles element from array here is code public class rand_select{ public static int Rand_partition( int a[],int p,int q,int i){ //smallest in a[p..q] if ( p==q) return a[p]; int r=partition (a,p,q); int k=r-p+1; if (i==k) return a[r]; if (i<k){ return Rand_partition(a,p,r-1,i); } return Rand_partition(a,r-1,q,i-k); } public static void main(String[]args){ int a[]=new int []{6,10,13,15,8,3,2,12}; System.out.println(Rand_partition(a,0,a.length-1,7)); } public static int partition(int a[],int p,int q){ int m=a[0]; while ( p<q){ while (p<q && a[p++] <m){ p++; } while (q>p && a[q--]>m){ q--; } int t=a[p]; a[p]=a[q]; a[q]=t; } int k=0; for (int i=0;i<a.length;i++){ if ( a[i]==m){ k=i; } } return k; } } but here is problem java.lang.ArrayIndexOutOfBoundsException please help me

    Read the article

  • partition from programming pearls

    - by davit-datuashvili
    hi suppose i have following array int a[]=new int[]{55,41,59,26,53,58,97,93}; i want to partition it around 55 so new array will be such } 41,26,53,55,59,58,93,93}; i have done such kinds of problems myself but this is from programming pearls and here code is like this we have some array[a..b] and given value t we write code following way int m=a-1; for i=[a..b] if ( array[i]<t) swap (++m;i); where swap function exchange two element in array at indexes ++m and i, i have run this program and it showed me mistake Exception java.lang.NullPointerException can anybody help me?

    Read the article

< Previous Page | 1 2 3 4 5 6  | Next Page >