当前位置: 首页>>代码示例>>C++>>正文


C++ ListElement类代码示例

本文整理汇总了C++中ListElement的典型用法代码示例。如果您正苦于以下问题:C++ ListElement类的具体用法?C++ ListElement怎么用?C++ ListElement使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ListElement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: while

bool LinkedList<T>::insertAtPos(T data, int pos)
{
	ListElement<T> *nodeToInsert = new ListElement<T>(data);
	if (nodeToInsert == nullptr) return false;

	// If list is empty and position is not the 
	// begining of the list return false. 
	if (isEmpty() && pos != 0) {
		return false;
	}

	ListElement<T> *curr = _head;
	// iterate until we are at pos - 1
	while (curr != nullptr && pos != 1) {
		curr = curr->getNext();
		pos--;
	}

	// insert the ListElement<T>
	if (pos == 1) {
		nodeToInsert->setNext(curr->getNext());
		curr->setNext(nodeToInsert);
		return true;
	}
	return false;
}
开发者ID:ajaykarri,项目名称:DataStructures,代码行数:26,代码来源:SinglyLinkedListTemplate.cpp

示例2: isExist

bool HashTable::isExist(string str)
{
    unsigned long long int index = hash->hash(str) % hTsize;
    if (table[index] != NULL && !table[index]->isEmpty())
    {
        ListElement *temp = table[index]->getHead();
        while(temp->getNext() != NULL)
        {
            if (temp->getStr() == str)
            {
                return true;
            }
            else
            {
                temp = temp->getNext();
            }
        }
        return temp->getStr() == str;
    }
    else
        return false;
}
开发者ID:antongulikov,项目名称:Homework,代码行数:22,代码来源:HashTable.cpp

示例3: gen_dict

void GenTree::gen_dict( const DictDecl *ad )
{
   if( ad->empty() ) {
      m_out->writeString( " =>" );
      return;
   }

   ListElement *iter = ad->begin();
   while( iter != 0 )
   {
      DictDecl::pair *pair = (DictDecl::pair *) iter->data();
      const Value *key = pair->first;
      const Value *value = pair->second;

      gen_value( key );
      m_out->writeString( "=>" );
      gen_value( value );
      iter = iter->next();
      if( iter != 0 )
         m_out->writeString( ", " );
   }
}
开发者ID:Klaim,项目名称:falcon,代码行数:22,代码来源:gentree.cpp

示例4: ListElement

void List::addAfterN(int nPos, int inValue)
{
	if (mLength >= nPos) {
		ListElement *additional = new ListElement(inValue);
		ListElement *current = mHead;
		for (int i = 1; i < nPos; i++) {
			current = current->getNext();
		}
		additional->setNext(current->getNext());
		current->setNext(additional);
		mLength++;
	}
}
开发者ID:AirVan21,项目名称:CPP,代码行数:13,代码来源:List.cpp

示例5: while

void LinkedList::insert(int position, int value)
{
    ListElement * le = head;
    while(le->getNext() != nullptr && position > 0)
    {
        position--;
        le = le->getNext();
    }

    if (position != 0)
    {
        std::cerr << "Error. The index is more then the length";
        deleteList();
        exit(0);
    }

    ListElement * newListEl = new ListElement();
    newListEl->takeValue(value);
    newListEl->takeNext(le->getNext());
    le->takeNext(newListEl);
}
开发者ID:artbez,项目名称:origin,代码行数:21,代码来源:linkedlist.cpp

示例6:

void LinkedList<T>::reverseList()
{
	if (isEmpty()) return;

	ListElement<T> *curr = _head;
	ListElement<T> *prev = curr->getNext();
	ListElement<T> *next = nullptr;

	// Iterate until we reach to the end of the list
	while (prev != nullptr) {
		curr->setNext(next);
		next = curr;
		curr = prev;
		prev = prev->getNext();
	}
	curr->setNext(next);

	// Set head to the current element
	_head = curr;
}
开发者ID:ajaykarri,项目名称:DataStructures,代码行数:20,代码来源:SinglyLinkedListTemplate.cpp

示例7: prepareLoader

void AppFalcon::runModule()
{
   ModuleLoader ml;
   prepareLoader( ml );

   // Create the runtime using the given module loader.
   Runtime runtime( &ml );

   // now that we have the main module, inject other requested modules
   ListElement *pliter = m_options.preloaded.begin();
   while ( pliter != 0 )
   {
      Module *module = ml.loadName ( * ( ( String * ) pliter->data() ) );
      runtime.addModule( module );

      // abandon our reference to the injected module
      module->decref();

      pliter = pliter->next();
   }

   // then add the main module
   Module* mainMod = loadInput(ml);
   runtime.addModule( mainMod );

   // abandon our reference to the main module
   mainMod->decref();

   //===========================================
   // Prepare the virtual machine
   //
   VMachineWrapper vmachine;

   //redirect the VM streams to ours.
   // The machine takes ownership of the streams, so they won't be useable anymore
   // after the machine destruction.
   readyStreams();
   vmachine->stdIn( m_stdIn );
   vmachine->stdOut( m_stdOut );
   vmachine->stdErr( m_stdErr );
   // I have given real process streams to the vm
   vmachine->hasProcessStreams( true );

   // push the core module
   // we know we're not launching the core module.
   vmachine->launchAtLink( false );
   Module* core = core_module_init();
   #ifdef NDEBUG
      vmachine->link ( core );
   #else
      LiveModule *res = vmachine->link ( core );
      fassert ( res != 0 ); // should not fail
   #endif
   core->decref();

   // prepare environment
   Item *item_args = vmachine->findGlobalItem ( "args" );
   fassert ( item_args != 0 );
   CoreArray *args = new CoreArray ( m_argc - m_script_pos );

   String ioEncoding = getIoEncoding();
   for ( int ap = m_script_pos; ap < m_argc; ap ++ )
   {
      CoreString *cs = new CoreString;
      if ( ! TranscodeFromString ( m_argv[ap], ioEncoding, *cs ) )
      {
         cs->bufferize ( m_argv[ap] );
      }

      args->append ( cs );
   }

   item_args->setArray ( args );

   Item *script_name = vmachine->findGlobalItem ( "scriptName" );
   fassert ( script_name != 0 );
   *script_name = new CoreString ( mainMod->name() );

   Item *script_path = vmachine->findGlobalItem ( "scriptPath" );
   fassert ( script_path != 0 );
   *script_path = new CoreString ( mainMod->path() );

   // Link the runtime in the VM.
   // We'll be running the modules as we link them in.
   vmachine->launchAtLink( true );
   if ( vmachine->link( &runtime ) )
   {
      vmachine->launch();

      if ( vmachine->regA().isInteger() )
         exitval( ( int32 ) vmachine->regA().asInteger() );
   }
}
开发者ID:Klaim,项目名称:falcon,代码行数:93,代码来源:falcon.cpp

示例8: oops_do

void List::oops_do(oopsDoFn f) {
  for (ListElement* e = Head(); e; e = e->Next())
    e->oops_do(f);
}
开发者ID:AdamSpitz,项目名称:self,代码行数:4,代码来源:list.cpp

示例9: addCommentAnnotations

void List::addCommentAnnotations(Scanner* scanner) {
  for (ListElement* e = Head(); e; e = e->Next())
   e->Data()->addCommentAnnotations(scanner);
}
开发者ID:AdamSpitz,项目名称:self,代码行数:4,代码来源:list.cpp

示例10: PrintSeparatedBy

void List::PrintSeparatedBy(char* sep) {
  for (ListElement* e = Head(); e; e = e->Next()) {
    e->Print();
    if (sep) lprintf("%s", sep);
  }
}
开发者ID:AdamSpitz,项目名称:self,代码行数:6,代码来源:list.cpp

示例11: main


//.........这里部分代码省略.........
   }

   bincode_stream = new FileStream;
   bincode_stream->open( input_file );

   if ( ! bincode_stream->good() )
   {
      stdOut->writeString( "falrun: Can't open file " );
      stdOut->writeString( input_file );
      stdOut->writeString( "\n" );
      stdOut->flush();
      return 1;
   }


   String module_name;
   String source_path;
   findModuleName( input_file, module_name );
   findModulepath( input_file, source_path );

   //-----------------------------------------
   // execute the script.
   //

   if ( source_path != "" )
      source_path += ";";

   try
   {
      ModuleLoader *modloader = new ModuleLoader( source_path + get_load_path() );
      Engine::setSearchPath( modloader->getSearchPath() );

      // set the module preferred language; ok also if default ("") is used
      modloader->setLanguage( module_language );

      Module *core = core_module_init();

      Module *main_mod = modloader->loadModule( bincode_stream );

      VMachine *vmachine = new VMachine(false);
      // change default machine streams.
      vmachine->stdIn( stdIn );
      vmachine->stdOut( stdOut );
      vmachine->stdErr( stdErr );
      vmachine->init();

      vmachine->link( core );
      core->decref();
      Runtime *runtime = new Runtime( modloader );

      // preload required modules

      ListElement *pliter = preloaded.begin();
      while( pliter != 0 )
      {
         Module *module = modloader->loadName( * ((String *) pliter->data()) );
         runtime->addModule( module );
         pliter = pliter->next();
      }

      Item *item_args = vmachine->findGlobalItem( "args" );
      fassert( item_args != 0 );
      CoreArray *args = new CoreArray( argc - script_pos );
      for ( int ap = script_pos; ap < argc; ap ++ ) {
         args->append( new CoreString( argv[ap] ) );
      }
      item_args->setArray( args );

      Item *script_name = vmachine->findGlobalItem( "scriptName" );
      fassert( script_name != 0 );
      script_name->setString( new CoreString( module_name ) );

      // the runtime will try to load the references.
      runtime->addModule( main_mod );

      if( vmachine->link( runtime ) )
      {
         vmachine->launch();

         if ( vmachine->regA().type() == FLC_ITEM_INT )
            return (int32) vmachine->regA().asInteger();

         return 0;
      }

      vmachine->finalize();
   }
   catch ( Error *err )
   {
      String temp;
      err->toString( temp );
      stdErr->writeString( "falcon: FATAL - Program terminated with error.\n" );
      stdErr->writeString( temp + "\n" );
      err->decref();
      return 1;
   }


   return 255;
}
开发者ID:Klaim,项目名称:falcon,代码行数:101,代码来源:falrun.cpp

示例12: while


//.........这里部分代码省略.........
      {

         const StmtWhile *wh = static_cast< const StmtWhile *>( cmp );
         m_out->writeString( "WHILE " );
         gen_value( wh->condition() );

         m_out->writeString( "\n" );
         gen_block( wh->children(), depth );
      }
      break;

      case Statement::t_loop:
      {
         const StmtLoop *wh = static_cast< const StmtLoop *>( cmp );
         m_out->writeString( "LOOP " );
         m_out->writeString( "\n" );
         gen_block( wh->children(), depth );

         if( wh->condition() != 0 )
         {
            m_out->writeString( "END LOOP WHEN " );
            gen_value( wh->condition() );
            m_out->writeString( "\n" );
         }
         else
            m_out->writeString( "END\n" );
      }
      break;

      case Statement::t_global:
      {
         m_out->writeString( "GLOBAL " );
         const StmtGlobal *sglobal = static_cast< const StmtGlobal *>( cmp );
         ListElement *iter = sglobal->getSymbols().begin();
         while ( iter != 0 ) {
            Symbol *sym = (Symbol *) iter->data();
            m_out->writeString( sym->name() + ", " );
            iter = iter->next();
         }
         m_out->writeString( "\n" );
      }
      break;

      case Statement::t_forin:
      {
         m_out->writeString( "FOR-IN " );
         const StmtForin *sfor = static_cast< const StmtForin *>( cmp );
         gen_array( sfor->dest() );
         m_out->writeString( " IN " );
         gen_value( sfor->source() );
         m_out->writeString( "\n" );
         gen_block( sfor->children(), depth );
         gen_block( sfor->firstBlock(), depth, "FORFIRST" );
         gen_block( sfor->middleBlock(), depth, "FORMIDDLE" );
         gen_block( sfor->lastBlock(), depth, "FORLAST" );
      }
      break;

      case Statement::t_try:
      {
         m_out->writeString( "TRY\n" );
         const StmtTry *stry = static_cast< const StmtTry *>( cmp );
         gen_block( stry->children(), depth );
         // generatest the switch integer list
         if ( ! stry->intCases().empty() )
         {
开发者ID:Klaim,项目名称:falcon,代码行数:67,代码来源:gentree.cpp

示例13: LL1

int SLLT::testLinkedList2()
{
	using namespace std;
	{
		LinkedList<char> LL1(new ListElement<char>('a'));
		LL1.insertAtEnd('b');
		LL1.insertAtEnd('c');
		LL1.insertAtEnd('d');
		LL1.insertAtEnd('e');
		cout << "L1 is empty :: " << LL1.isEmpty() << "L1 size : " << LL1.getSize() << endl;
		LL1.display();
		LL1.insertAtHead('f');
		cout << "After insert 10 at head L1 size : " << LL1.getSize() << endl;
		LL1.display();

		LL1.insertAtEnd('g');
		cout << "After insert at end L1 size : " << LL1.getSize() << endl;
		LL1.display();

		LL1.deleteElement(new ListElement<char>('c'));
		cout << "after delete 6 L1 size : " << LL1.getSize() << endl;
		LL1.display();

		ListElement<char> *le = LL1.find('c');
		if (le) {
			cout << "L1 find :" << le->getValue() << endl;
		}
		else {
			cout << "not found " << endl;
		}

		LL1.recursiveReverseList();
		cout << "L1 after recursive reverse : size:  " << LL1.getSize() << endl;
		LL1.display();

		LL1.reverseList();
		cout << "L1 after  reverse : size:  " << LL1.getSize() << endl;
		LL1.display();

		LinkedList<char> LL2(new ListElement<char>('c'));
		LL2.insertAtEnd('a');
		LL2.insertAtEnd('b');

		cout << "L2 size : " << LL2.getSize() << endl;
		//LinkedList<T><int> LL = LL1.sumLists(LL1, LL2);
		LL2.display();
		LL1 = LL2;

		cout << "are list same: " << LinkedList<char>::compareList(&LL1, &LL2) << endl;
		cout << "L1 size : " << LL1.getSize() << endl;
		cout << "L2 size : " << LL1.getSize() << endl;
		LL1.display();
		LL2.display();

		LinkedList<char> LL3 = LL2;
		LL3.display();
		cout << "are LL2 & LL3 same: " << LinkedList<char>::compareList(&LL2, &LL3) << endl;

		LL3.reverseList();
		cout << "L3 after reverse : size:  " << LL3.getSize() << endl;
		LL3.display();

	}
	getchar();

	return 0;
}
开发者ID:ajaykarri,项目名称:DataStructures,代码行数:67,代码来源:SinglyLinkedListTemplate.cpp

示例14: copy

	ListElement<T>* copy()
	{
		return new ListElement(data, (next?next->copy():0));
	}
开发者ID:dongbeibei,项目名称:data_structure,代码行数:4,代码来源:linkTemplate.cpp

示例15: switch

void MainWindow::ItemDoubleClicked( QListWidgetItem *Item )
{
    if( Item == mMoreItems )
    {
        if( !mCurContent.isNull() && mCurContent->getType() == IT_VideoFeed )
            mParser->ParseNextPage(  mCurContent->cast_VideoFeed() );
        delete mMoreItems; mMoreItems = 0;
        return;
    }
    QWidget *Widget = Item->listWidget()->itemWidget(Item);
    if( Widget && typeid(*Widget) == typeid(ListElement) )
    {
        BasePtr Info = static_cast<ListElement*>(Widget)->getInfo();

        ui->ItemContent->clear();
        switch( Info->getType() ) {
        case( IT_VideoInfo ):
            {
                QListWidgetItem *Item = new QListWidgetItem( ui->ItemContent );
                Item->setSizeHint( QSize(300,64) );
                ListElement *Widget = new ListElement;
                Widget->setInfo( Info->cast_VideoInfo()->Releated->cast_BaseInfo() );
                Widget->setSelected(false);
                ui->ItemContent->setItemWidget( Item, Widget );

                Item = new QListWidgetItem( ui->ItemContent );
                Item->setSizeHint( QSize(300,64) );
                Widget = new ListElement;
                Widget->setInfo( Info->cast_VideoInfo()->Responces->cast_BaseInfo() );
                Widget->setSelected(false);
                ui->ItemContent->setItemWidget( Item, Widget );
                break;
            }
        case( IT_VideoFeed ): {
            if( Info->cast_VideoFeed()->ParsedPages == 0 ) {
                mParser->ParseNextPage(Info->cast_VideoFeed() );
                mCurContent = Info;
                return;
            }
                VideoFeedPtr fInfo = Info->cast_VideoFeed();
                for( int i=0; i < fInfo->Content.size(); i++ ) {
                    QListWidgetItem *Item = new QListWidgetItem( ui->ItemContent );
                    Item->setSizeHint( QSize(300,64) );
                    ListElement *Widget = new ListElement;
                    Widget->setInfo( fInfo->Content.at(i)->cast_BaseInfo() );
                    Widget->setSelected(false);
                    ui->ItemContent->setItemWidget( Item, Widget );
                }
                if( !fInfo->HasFullFeed ) {
                    /// this can seem like a memory leek but it is not, then ItemContent is cleared this element is also deleted :)
                    mMoreItems = new QListWidgetItem( "Double click for more!", ui->ItemContent );
                }
            break;
        } case( IT_UserInfo ): {
                // Fix this
                UserPtr User = Info->cast_UserInfo();

                QListWidgetItem *Item = 0;
                ListElement *Widget = 0;

                Item = new QListWidgetItem( ui->ItemContent );
                Item->setSizeHint( QSize(300,64) );
                Widget = new ListElement;
                Widget->setInfo( User->Favorites->cast_BaseInfo() );
                Widget->setSelected(false);
                ui->ItemContent->setItemWidget( Item, Widget );

                Item = new QListWidgetItem( ui->ItemContent );
                Item->setSizeHint( QSize(300,64) );
                Widget = new ListElement;
                Widget->setInfo( User->Uploads->cast_BaseInfo() );
                Widget->setSelected(false);
                ui->ItemContent->setItemWidget( Item, Widget );

                /* This does not work... I think its something with my parser....
                   have to look it up, maybe something with that it never parsed the playlists...
                   Solved it, I think forgot to create a playlist feed :P */
                Item = new QListWidgetItem( ui->ItemContent );
                Item->setSizeHint( QSize(300,64) );
                Widget = new ListElement;
                Widget->setInfo( User->Playlists->cast_BaseInfo() );
                Widget->setSelected(false);
                ui->ItemContent->setItemWidget( Item, Widget );

                break;
            break;
        } case( IT_PlaylistFeed ):
            /// @todo
            break;
        case( IT_ChannelFeed ):
            /// @todo
            break;
        default:
            break;
        }
        mCurContent = Info;
    }
}
开发者ID:Visse,项目名称:QTYoutubeViewer,代码行数:98,代码来源:MainWindow.cpp


注:本文中的ListElement类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。