Exemplo n.º 1
0
bool Gobby::FindDialog::find()
{
	if(get_direction() == SEARCH_FORWARD)
		return find_next();
	else
		return find_previous();
}
Exemplo n.º 2
0
// problem 2.3
Node* find_previous(Node *root) 
{
  if(root==NULL)
  {
    return root;
  }
  Node * parent=root->parent;
  if(root->a != NULL)
  {
    return find_largest(root->a);
  }
  if(parent==NULL)
  {
    return parent;
  }
  if(parent->c!=NULL && parent->c->value==root->value)
  {
    if(parent->b!=NULL)
      return find_largest(parent->b);
    else
      return parent;
  }
   if(parent->b!=NULL && parent->b->value==root->value)
  {
      return parent;
  }
  if(parent->a!=NULL && parent->a->value==root->value)
  {
      return find_previous(parent);
  }
}
Exemplo n.º 3
0
int main() {

  Node* root = NULL;

  // create the diagram on the test handout
  insert(root,30);
  insert(root,10);
  insert(root,32);
  insert(root,70);
  insert(root,5);
  insert(root,16);
  insert(root,24);
  insert(root,31);
  insert(root,52);
  insert(root,64);
  insert(root,92);
  insert(root,200);
  insert(root,12);
  insert(root,19);
  insert(root,45);
  insert(root,59);
  insert(root,150);
  insert(root,210);
  insert(root,450);
  insert(root,13);
  insert(root,4);
  insert(root,1);

  // print the tree before iteration
  print(root,"");
  std::cout << std::endl;
  std::cout << std::endl;

  // loop over the structure
  int count = 0;
   Node *tmp = find_largest(root);
   std::cout<<tmp->value;
  int prev = tmp->value;
  while (tmp != NULL) {
    std::cout << tmp->value << " ";
    tmp = find_previous(tmp);
    if (tmp != NULL) { 
      assert (prev > tmp->value);
      prev = tmp->value;
    }
    count++;
  }
  std::cout << std::endl;
  assert (count == 22);

  // cleanup so we have no memory leaks
  destroy (root);
}
Exemplo n.º 4
0
//删除一个元素
//如果该元素在表中,则删除,否则不处理(不在表中那么is_last)
void delete_node(element_type x, List L)
{
	position p;
	position tmp_cell;

	p = find_previous(x, L);

	if (!is_last(p, L)) {
		tmp_cell = p->next;
		p->next = tmp_cell->next;
		free(tmp_cell);
	}
}
Exemplo n.º 5
0
void
cmdfindprev_clicked (GtkWidget *widget)
{
    const gchar *text = gtk_entry_get_text (GTK_ENTRY (entry_text));
    GtkTextSearchFlags flags = GTK_TEXT_SEARCH_TEXT_ONLY;
    
    if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (chkCase)))
        flags = flags | GTK_TEXT_SEARCH_CASE_INSENSITIVE;

    if (!find_previous (text_view, text, flags))
    {
        //Status Bar show cannot find text
    }
    search_text = g_strdup (text);
}
Exemplo n.º 6
0
bool
delete_node(ldata d, list l)
{
	pnode ptmp = NULL;

	if (l == NULL) {
		fprintf(stderr,
			"can not delete a node from a null list!(delete_node)\n");
		return false;
	}

	l = find_previous(d, l);
	if (l != NULL) {
		ptmp = l->next;
		l->next = l->next->next;
		free(ptmp);
	}
	return true;
}
}

position find(element_type x,LIST *L)
{
  postion p;
  p=CURSOR_SPACE[L].next;
  while(p&&CURSOR_SPACE[p].element!=x)
    p=CURSOR_SPACE[p].next;
  *L=p;
  return p;
} 

void delete(element_type x,LIST L)
{
  positon p,tmp_cell;
  p=find_previous(x,L);
  if(!is_last(p,L)){
    tmp_cell=CURSOR_SPACE[p].next;
    CURSOR_SPACE[p].next=CURSOR_SPACE[tmp_cell].next;
    cursor_free(tmp_cell);
  }
}

void insert(element_type x,LIST L,position p)
{
  position tmp;
  tmp=cursor_alloc();
  if(tmp==0)
    fatal_error("OUT OF SPACE!!");
  else{
    CURSOR_SPACE[tmp].element=x;
Exemplo n.º 8
0
Arquivo: poly.c Projeto: gitpan/GH
static void trim_polyA_align(struct edit_script_list **Sptr, Exon *lblock, Exon **exons, const int bc, int *pA, uchar *s1,uchar *s2) 
{
    edit_script_list *head = *Sptr;
    edit_script *tp;
    int tmpi = 0, num, idents = 0;
    uchar *a, *b;
    Exon *prev;

    int i, j;  /* i index in the cDNA */

    if (bc>head->offset2+head->len2-1) {
        *pA = bc;
        return;
    }

    if (bc==head->offset2) {
        /* cDNA gap: remove the entire script; this should be properly sorted */
        *Sptr = head->next_script;
        Free_script(head->script);
        free(head);
        while ((*exons)->from2>=bc) {
           prev = find_previous(lblock,*exons);
           prev->next_exon = (*exons)->next_exon;
           free(*exons); *exons = prev;
        }
        *pA = bc;
        return;
    }

    Flip_script(&(head->script));
    i = head->offset2 + head->len2 -1;
    j = head->offset1 + head->len1 -1;
    tp = head->script;

    while (i>=bc && tp) {
       num = tp->num;
       switch (tp->op_type) {
          case INSERT:
                   if (i>=bc && bc>i-num+1) {
                       tmpi += i-bc+1; tp->num -= i-bc+1; i = bc-1;
                   } else {
                       i -= num; tmpi += num; head->script = tp->next;
                       free(tp); tp = head->script;
                   }
                   break;
          case DELETE:
                   j -= num; tmpi += num; head->script = tp->next;
                   free(tp); tp = head->script;
                   break;
          case SUBSTITUTE:
                   if (i>=bc && bc>i-num+1) {
                       a = s2+i-1; b = s1+j-1;
                       while (a>=s2+bc-1) {
                          if (*a--!=*b--) tmpi++; else idents++;
                       }
                       j -= i-bc+1; tp->num -= i-bc+1; i = bc-1;
                   } else {
                       /* at most 1 nt remaining */
                       a = s2+i-1; b = s1+j-1;
                       while (a>=s2+i-num) {
                          if (*a--!=*b--) tmpi++; else idents++;
                       }

                       i -= num; j -= num;
                       head->script = tp->next;
                       free(tp); tp = head->script;
                   }
                   break;
          default: fatalf("Unrecognized opcode %d.\n",tp->op_type);
       }
       /* indel walk */
    }
    assert(i==bc-1);

    while (tp->op_type!=SUBSTITUTE && j+1>=(*exons)->from1) {
       if (tp->op_type==INSERT) {
           i -= tp->num; tmpi += tp->num;
       } else if (j<(*exons)->from1 && i<(*exons)->from2) {
           j -= tp->num;
       } else {
           j -= tp->num; tmpi += tp->num;
       }
       head->script = tp->next;
       free(tp); tp = head->script;
    }

    if (head->script==NULL) {
        *Sptr = head->next_script;
        free(head);
    } else {
        head->len1 = j-head->offset1+1;
        head->len2 = i-head->offset2+1;
        head->score -= tmpi;
        Flip_script(&(head->script));
    }

    if ((*exons)->from2>i) {
        prev = find_previous(lblock,*exons);
        prev->next_exon = (*exons)->next_exon;
        free(*exons); *exons = prev;
    } else {
        double tmp_matches;
        (*exons)->to2 = i;
        (*exons)->to1 = j;
        (*exons)->length = (*exons)->to2-(*exons)->from2+1;
        tmp_matches = (*exons)->nmatches - idents;
        (*exons)->alen -= tmpi+idents;
        (*exons)->match = (int)(100*tmp_matches/(*exons)->alen);
    }
    *pA = i+1;

    return;
}
Exemplo n.º 9
0
TextRoom::TextRoom(QWidget *parent, Qt::WFlags f)
		: QWidget(parent, f), sentenceTally(0)
{
	setupUi(this);
	setObjectName("textroom");

// Set the default values for variables.
	numChanges = 0;
	prevLength = 0;
	wordcount = 0;
	alarm = 0;
	parasold = 0;
	isHighlighted = false;

#ifdef Q_OS_MACX
	// Find the path for the app path 
	QDir tmpDir = QDir(QCoreApplication::applicationDirPath());
	// go into Resources folder
	tmpDir.cdUp();
	tmpDir.cd("Resources");
	// get the full path for the resources
	resourcesDir = tmpDir.path();
#endif

// Create the dialog windows.
	optionsDialog = new OptionsDialog(this);
	helpDialog = new HelpDialog(this);
	selectFont = new SelectFont(this);
	aboutDialog = new AboutDialog(this);
	scratchDialog = new ScratchDialog(this);
	miniFlo = new MiniFlo(this);
	getAWord = new GetAWord(this);
	musicRoom = new MusicRoom(this);
	googleDocsDialog = new GoogleDocsDialog(this);	

// Read settings saved by Options Dialog.
#ifdef Q_OS_WIN32
	settings = new QSettings(QSettings::IniFormat, QSettings::UserScope, QApplication::applicationName());
#else
	settings = new QSettings();
#endif
	readSettings();

// Sound adjustments.
	int audio_rate = 11025;
	Uint16 audio_format = AUDIO_S16SYS;
	int audio_channels = 2;
	int audio_buffers = 1024;
	
	if ( SDL_Init(SDL_INIT_AUDIO) < 0 ) {
		fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());
		exit(1);
	}
	atexit(SDL_Quit);
	
	if(Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers) != 0) {
		printf("Unable to initialize audio: %s\n", Mix_GetError());
		exit(1);
	}

// Load sounds.
#ifdef Q_OS_WIN32
	soundenter = Mix_LoadWAV("keyenter.wav");
#elif defined(Q_OS_MACX)
	QString tmp = resourcesDir;
	tmp.append("/sounds/keyenter.wav");
	soundenter = Mix_LoadWAV(tmp.toAscii());
#else
	soundenter = Mix_LoadWAV("/usr/share/sounds/keyenter.wav");
#endif
	if(soundenter == NULL) {
		printf("Unable to load WAV file: %s\n", Mix_GetError());
	}

#ifdef Q_OS_WIN32
	soundany = Mix_LoadWAV("keyany.wav");
#elif defined(Q_OS_MACX)
	tmp = resourcesDir;
	tmp.append("/sounds/keyany.wav");
	soundany = Mix_LoadWAV(tmp.toAscii());
#else
	soundany = Mix_LoadWAV("/usr/share/sounds/keyany.wav");
#endif
	if(soundany == NULL) {
		printf("Unable to load WAV file: %s\n", Mix_GetError());
	}
		
// Create the keyboard shortcuts.
	new QShortcut ( QKeySequence(QKeySequence::New), this, SLOT( newFile() ) );
	new QShortcut ( QKeySequence(QKeySequence::Open), this, SLOT( open() ) );
	new QShortcut ( QKeySequence(QKeySequence::Save), this, SLOT( save() ) );
	new QShortcut ( QKeySequence(QKeySequence::HelpContents), this, SLOT( help() ) );
#ifdef Q_OS_MACX
	new QShortcut ( QKeySequence(tr("F1", "Help")), this, SLOT( help() ) );
#endif
	new QShortcut ( QKeySequence(tr("F2", "Options")), this, SLOT( options() ) );
	new QShortcut ( QKeySequence(tr("F3", "About")), this, SLOT( about() ) );
	new QShortcut ( QKeySequence(tr("F5", "Spell Check")), this, SLOT( spellCheck() ) );
	new QShortcut ( QKeySequence(tr("F6", "Scratch Pad")), this, SLOT( showScratchPad() ) );
	new QShortcut ( QKeySequence(tr("Ctrl+P", "Print")), this, SLOT( print() ) );
	new QShortcut ( QKeySequence(tr("Shift+Ctrl+S", "Save As")), this, SLOT( saveAs() ) );
	new QShortcut ( QKeySequence(tr("Ctrl+D", "Insert Date")), this, SLOT( insertDate() ) );
	new QShortcut ( QKeySequence(tr("Ctrl+T", "Insert Time")), this, SLOT( insertTime() ) );	
	new QShortcut ( QKeySequence(tr("Ctrl+Q", "Quit Application")) , this, SLOT( close() ) );
	new QShortcut ( QKeySequence(tr("Alt+F4", "Quit Application")) , this, SLOT( close() ) );
	new QShortcut ( QKeySequence(tr("Ctrl+F", "Find Text")) , this, SLOT( find() ) );
	new QShortcut ( QKeySequence(tr("F11", "Toggle Fullscreen")) , this, SLOT( toggleFullScreen() ) );
	new QShortcut ( QKeySequence(tr("Esc", "Toggle Fullscreen")) , this, SLOT( toggleEscape() ) );
	new QShortcut ( QKeySequence(tr("Ctrl+M", "Minimize TextRoom")) , this, SLOT( showMinimized() ) );
	new QShortcut ( QKeySequence(tr("F4", "Find Next")) , this, SLOT( find_next() ) );
	new QShortcut ( QKeySequence(tr("Ctrl+F4", "Find Previous")) , this, SLOT( find_previous() ) );
	new QShortcut ( QKeySequence(tr("Ctrl+B", "Bold")) , this, SLOT( textBold() ) );
	new QShortcut ( QKeySequence(tr("Ctrl+I", "Italic")) , this, SLOT( textItalic() ) );
	new QShortcut ( QKeySequence(tr("Ctrl+Up", "Increase Text Size")) , this, SLOT( textSizeUp() ) );
	new QShortcut ( QKeySequence(tr("Ctrl+Down", "Decrease Text Size")) , this, SLOT( textSizeDown() ) );	
	new QShortcut ( QKeySequence(tr("Ctrl+W", "Select Font")) , this, SLOT( changeFont() ) );	
        new QShortcut ( QKeySequence(tr("Ctrl+R", "Align Right")) , this, SLOT( alignRight() ) );
        new QShortcut ( QKeySequence(tr("Ctrl+L", "Align Left")) , this, SLOT( alignLeft() ) );
        new QShortcut ( QKeySequence(tr("Ctrl+J", "Align Justify")) , this, SLOT( alignJustify() ) );
        new QShortcut ( QKeySequence(tr("Ctrl+E", "Align Center")) , this, SLOT( alignCenter() ) );
        new QShortcut ( QKeySequence(tr("Ctrl+Alt+I", "Insert Image")) , this, SLOT( insertImage() ) );
        new QShortcut ( QKeySequence(tr("F7", "Show MiniFlo")) , this, SLOT( showMiniFlo() ) );
        new QShortcut ( QKeySequence(tr("F8", "Get A Word")) , this, SLOT( showGetAWord() ) );
        new QShortcut ( QKeySequence(tr("F9", "MusicRoom")) , this, SLOT( showMusicRoom() ) );
        new QShortcut ( QKeySequence(tr("F10", "Google Docs")) , this, SLOT( exportToGoogle() ) );
	// Service: show cursor
	new QShortcut ( QKeySequence(tr("Shift+F4", "Show Cursor")) , this, SLOT( sCursor() ) );

	//fw = new QFileSystemWatcher(this);
	//fw->addPath( settings->fileName() );

	// If file is changed, read the settings->
	//connect(fw, SIGNAL(fileChanged(const QString)),
	//		this, SLOT(readSettings()));
	// If the document is changed, do some stuff.
	connect(textEdit->document(), SIGNAL(contentsChanged()),
		this, SLOT(documentWasModified()));

	// If position is changed, scroll.
	connect(textEdit->verticalScrollBar(), SIGNAL(valueChanged(int)),
		this, SLOT(vPositionChanged()));
	// If horizontal scrollar is changed, scroll.
	connect(horizontalSlider, SIGNAL(valueChanged(int)),
		this, SLOT(hSliderPositionChanged()));
	connect(textEdit, SIGNAL(anchorClicked(QUrl)), this, SLOT(showScratchPad()));

	// check if we need to open some file at startup
	const QStringList args = QCoreApplication::arguments();
	if (args.count() == 2)
	{
		QFile file( args.at(1) );
		if ( file.exists() )
			curFile = args.at(1);
	}
	
	if (!curFile.isEmpty())
		loadFile(curFile);
	else
		newFile();


	// set cursor position
	if ( isSaveCursor )
	{
		textEdit->textCursor().setPosition(cPosition);
	}

	writeSettings();

// Refresh the file status every second.
	QTimer *timer = new QTimer(this);
	connect(timer, SIGNAL(timeout()), this, SLOT(getFileStatus()));
	timer->start(1000);
}
Exemplo n.º 10
0
void
Sim4::trim_polyA_align(struct edit_script_list **Sptr, Exon *lblock, Exon **exons, const int bc, int *pA, char *s1,char *s2) 
{
  edit_script_list *head = *Sptr;
  edit_script *tp;
  int tmpi = 0, num, idents = 0, identsN = 0;
  char *a, *b;
  Exon *prev;

  int i, j;  /* i index in the cDNA */

  if (bc>head->offset2+head->len2-1) {
    *pA = bc;
    return;
  }

  if (bc==head->offset2) {
    /* cDNA gap: remove the entire script; is this properly sorted? LLL */
    *Sptr = head->next_script;
    Free_script(head->script);
    ckfree(head);
    while ((*exons)->frEST>=bc) {
      prev = find_previous(lblock,*exons);

      if (prev == 0L) {
        fprintf(stderr, "trim_polyA_align(): Corrupted exon list, cannot find the previous exon (remove entire script).\n");
        for (; lblock; lblock = lblock->next_exon)
          fprintf(stderr, "  GEN f=%8d t=%8d  EST f=%8d t=%8d   flag=%d\n",
                  lblock->frGEN, lblock->toGEN, lblock->frEST, lblock->toEST, lblock->flag);
        kill(getpid(), SIGKILL);
      }

      prev->next_exon = (*exons)->next_exon;
      //freeExon(*exons);  garbage collected
      *exons = prev;
    }
    *pA = bc;
    return;
  }

  Flip_script(&(head->script));
  i = head->offset2 + head->len2 -1;
  j = head->offset1 + head->len1 -1;
  tp = head->script;

  while (i>=bc && tp) {
    num = tp->num;
    switch (tp->op_type) {
      case INSERT:
        if (i>=bc && bc>i-num+1) {
          (*exons)->numInDel -= i - bc + 1;
          (*exons)->numEdits -= i - bc + 1;
          tmpi    += i-bc+1;
          tp->num -= i-bc+1;
          i        = bc-1;
        } else {
          (*exons)->numInDel -= num;
          (*exons)->numEdits -= num;
          tmpi += num;
          i    -= num;
          head->script = tp->next;
          ckfree(tp);
          tp = head->script;
        }
        break;
      case DELETE:
        (*exons)->numInDel -= num;
        (*exons)->numEdits -= num;
        j    -= num;
        tmpi += num;
        head->script = tp->next;
        ckfree(tp);
        tp = head->script;
        break;
      case SUBSTITUTE:
        if (i>=bc && bc>i-num+1) {
          a = s2+i-1; b = s1+j-1;
          while (a>=s2+bc-1) {
            if (*a != *b) {
              (*exons)->numEdits--;
              tmpi++;
            } else {
              if (*a == 'N') {
                (*exons)->numNs--;
                identsN++;
              } else {
                (*exons)->numMatches--;
                idents++;
              }
            }
            a--;
            b--;
          }
          j -= i-bc+1; tp->num -= i-bc+1; i = bc-1;
        } else {
          /* at most 1 nt remaining */
          a = s2+i-1; b = s1+j-1;
          while (a>=s2+i-num) {
            if (*a != *b) {
              (*exons)->numEdits--;
              tmpi++;
            } else {
              if (*a == 'N') {
                (*exons)->numNs--;
                identsN++;
              } else {
                (*exons)->numMatches--;
                idents++;
              }
            }
            a--;
            b--;
          }

          i -= num; j -= num;
          head->script = tp->next;
          ckfree(tp);
          tp = head->script;
        }
        break;
#if 0
      default:
        fatalf("Unrecognized opcode %d.\n",tp->op_type);
#endif
    }
    /* indel walk */
  }
  assert(i==bc-1);

  while ((tp != 0L) &&
         (tp->op_type != SUBSTITUTE) && (j+1 >= (*exons)->frGEN)) {
    if (tp->op_type==INSERT) {
      i -= tp->num;
      tmpi += tp->num;
      (*exons)->numInDel -= tp->num;
      (*exons)->numEdits -= tp->num;
    } else if (j<(*exons)->frGEN && i<(*exons)->frEST) {
      j -= tp->num;
    } else {
      j -= tp->num;
      tmpi += tp->num;
      (*exons)->numInDel -= tp->num;
      (*exons)->numEdits -= tp->num;
    }
    head->script = tp->next;
    ckfree(tp);
    tp = head->script;
  }

  if (head->script==NULL) {
    *Sptr = head->next_script;
    ckfree(head);
  } else {
    head->len1 = j-head->offset1+1;
    head->len2 = i-head->offset2+1;
    head->score -= tmpi;
    Flip_script(&(head->script));
  }

  if ((*exons)->frEST>i) {
    prev = find_previous(lblock,*exons);

    if (prev == 0L) {
      fprintf(stderr, "trim_polyA_align(): Corrupted exon list, cannot find the previous exon (frEST).\n");
      for (; lblock; lblock = lblock->next_exon)
        fprintf(stderr, "  GEN f=%8d t=%8d  EST f=%8d t=%8d   flag=%d\n",
                lblock->frGEN, lblock->toGEN, lblock->frEST, lblock->toEST, lblock->flag);
      kill(getpid(), SIGKILL);
    }

    prev->next_exon = (*exons)->next_exon;
    //freeExon(*exons);  garbage collected
    *exons = prev;
  } else {
    (*exons)->toEST = i;
    (*exons)->toGEN = j;
    (*exons)->length = (*exons)->toEST-(*exons)->frEST+1;

    (*exons)->alignmentLength = ((*exons)->toGEN - (*exons)->frGEN + 1 +
                                 (*exons)->toEST - (*exons)->frEST + 1 +
                                 (*exons)->numInDel);
    (*exons)->percentID   = computePercentIdentity((*exons)->numEdits,
                                                   (*exons)->alignmentLength);
  }
  *pA = i+1;

  return;
}
Exemplo n.º 11
0
Arquivo: list.c Projeto: gentio/4115

struct list *find_previous(struct list *head, int x)
{
    struct list *temp;
    temp = head;

    while (temp->next != NULL && temp->next->x != x)
    temp = temp->next;
    return temp;
}

void delete(struct list *head, int x)
{
    struct list *temp, *delete;
    temp = find_previous(head, x);
    if(!islast(temp)){
        delete = temp->next;
        temp->next = delete->next;
        free(delete);
    }
}

void print_list(struct list *head)
{
    struct list  *curt;
    curt = head;
    while(curt != NULL){
        printf("x: %d y: %d\n", curt->x, curt->y);
        curt = curt->next;
    }