2 Replies - 5144 Views - Last Post: 11 April 2012 - 07:38 AM Rate Topic: -----

#1 sashberd   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 11-April 12

convert c++ code to c# code

Posted 11 April 2012 - 07:30 AM

Hi guys

I have to convert code from c++ to c# for my job.

I almost finished , but I have some problem with next function:
double sprod_ss(SVECTOR *a, SVECTOR *B)/> 
    
{
    register double sum=0;
    register WORD *ai,*bj;
    ai=a->words;
    bj=b->words;
    while (ai->wnum && bj->wnum) {
      if(ai->wnum > bj->wnum) {
	bj++;
      }
      else if (ai->wnum < bj->wnum) {
	ai++;
      }
      else {
	sum+=(ai->weight) * (bj->weight);
	ai++;
	bj++;
      }
    }
    return((double)sum);





My problem is in "while" loop. Since in my conversation of classes a->words is a List<Word> type a cant use
while (ai->wnum && bj->wnum)
I tried a different ways to convert but the program does not work as well.
Any help

Thanks

Is This A Good Question/Topic? 0
  • +

Replies To: convert c++ code to c# code

#2 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6260
  • View blog
  • Posts: 24,030
  • Joined: 23-August 08

Re: convert c++ code to c# code

Posted 11 April 2012 - 07:33 AM

Show your attempt, and we'll help you out.
Was This Post Helpful? 1
  • +
  • -

#3 sashberd   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 11-April 12

Re: convert c++ code to c# code

Posted 11 April 2012 - 07:38 AM

I`ve tried something like this:

 public double sprod_ss(SVector a, SVector B)/> 
	 /* compute the inner product of two sparse vectors */
{
     double sum=0;
     List<Word> ai=a.words;
     List<Word> bj=a.words;
     int i=0,k=0;
    
     for(;i<ai.Count;){
         for(;k<bj.Count;){
             if(ai[i].WordNum > bj[k].WordNum) {
    k++;
      }
      else if (ai[i].WordNum <bj[k].WordNum) {
    i++;
      }
      else {
    sum+=(ai[i].WordWeight) * (bj[k].WordWeight);
          i++;
          k++;
      }
         }
     }
     
     
     return((double)sum);


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1