vector<std::string> Split(std::string str, char delimiter) //takes a string and a delimiter as parameters and //returns the corresponding vector of strings { vector<std::string> splittedString; unsigned int i =0; unsigned int k=0; //number of characters between two delimiters while(i<str.size()) { while(i<str.size() && str[i]!=delimiter) //i<str.size() if not str[i] could be out of range { i++; k++; } //str[i] is now a delimiter or i is out of range, even if we did not enter the while if(k>0) //that means we entered the second while and that there is a string between two delimiters //i may be equal to str.size() but as k>0, i-k and i-k-1 (the last char of substr(i-k,k)) are not out of range { InsertEnd(splittedString, str.substr(i-k,k)); //add the string between two delimiters (w/o them) to the vector splitted String //(i because str[i-k-1] is a delimiter) } else //that means there is no string { InsertEnd(splittedString, ""); //we want to know there are two delimiters with nothing between them } i++; k=0; } if(str[str.size()-1] = delimiter) { InsertEnd(splittedString, ""); //if a delimiter is at the end of the string, it will take it into account //and add "" at the end of the vector : when we split e.g "52;Chateau de Vincennes;1;" we want splittedString.size()=4 } return splittedString; }
int main() { struct SLL* head = NULL; //Ek head declare kardiya bas InsertEnd(&head,6); //DeleteEnd(&head); InsertStart(&head,7); InsertStart(&head,1); InsertEnd(&head,4); InsertAfter(head->next,8); printList(head); DeleteEnd(&head); printf("\n"); printList(head); DeleteStart(&head); printf("\n"); printList(head); DeleteComplete(&head); printList(head); return 0; }
//-------------------------------------------------------------------// // AddItemsFromDragData() // //-------------------------------------------------------------------// // Does the actual work of ripping items from the drag data and // adding them to the list control. //-------------------------------------------------------------------// bool OleListCtrl::AddItemsFromDragData( int nUnderCursor, bool bInsertAfter, CPoint DropPoint ) { InsertStart(); // Loop variables. CRect ItemRect; bool bFirstItem = true; // If nUnderCursor is not valid, we should be at the bottom of // the list. if ( nUnderCursor < 0 ) nUnderCursor = GetItemCount(); // Adjust nUnderCursor to always be before. if ( bInsertAfter ) nUnderCursor++; // Add the items to the list. int i; for ( i = 0; i < Items.GetSize(); i++ ) { // Add it to the list. // The string contains all column text. Break it // back down. CString* pstrFull = &Items[i].m_strName; int nStartPos = pstrFull->Find( ctColumnSeparator ); CString strText = pstrFull->Left( nStartPos ); // We need to include the text and // the data stored in the lParam. int nNewIndex = InsertItem( LVIF_TEXT | LVIF_PARAM, // UINT nMask, nUnderCursor + i, // int nItem, LPCTSTR( strText ), // LPCTSTR lpszItem, 0, // UINT nState, 0, // UINT nStateMask, 0, // int nImage, Items[i].m_lParam // LPARAM lParam ); ASSERT( nNewIndex == nUnderCursor + i ); // Set the checked state. CheckItem( nNewIndex, Items[i].m_bChecked ); // Mark all the dropped items as selected. // WARNING: Don't try to do this until later, so we don't // end up adding to the original moved selection that is // to be deleted. m_vnNewlyDroppedItems.push_back( nNewIndex ); // Set the text of the subitems, if any. int nStopPos; int nCol; for ( nCol = 1; nCol < GetAbsoluteColCount(); nCol++ ) { // Get the next stop position. nStopPos = pstrFull->Find( ctColumnSeparator, nStartPos + 1 ); // Extract the col string. if ( nStopPos == -1 ) strText = pstrFull->Mid( nStartPos + 1 ); else strText = pstrFull->Mid( nStartPos + 1, nStopPos - nStartPos - 1 ); // Do the deed. SetItemText( nUnderCursor + i, nCol, strText ); // Set up for next col. nStartPos = nStopPos; } // Set the position of the item based on the drop // point and the number in the RefItems array. // The first item needs a different calc. We didn't do it // outside the loop because it was easier to get the size // of the item bitmap here. if ( bFirstItem ) { // Calculate the starting drop point. bFirstItem = false; GetItemRect( 0, &ItemRect, LVIR_ICON ); DropPoint.x -= ( ItemRect.Width() / 2 ); DropPoint.y -= ( ItemRect.Height() / 2 ); } else { // This aligns multiple items out to the right. DropPoint.x += ItemRect.Width() + nDropXMargin; } // Now set it, if available. if ( (GetStyle() & LVS_OWNERDATA)==0 ) SetItemPosition( nUnderCursor + i, DropPoint ); // Provide a post-insert-item virtual function. OnAddDroppedItem( nUnderCursor + i ); } InsertEnd(); // We want to return true only if we processed items. // bFirstItem can tell us this. return !bFirstItem; }
//-------------------------------------------------------------------// // BeginDrag() //-------------------------------------------------------------------// // This function attempts a drag when the left button has been // pressed on an item. It returns true if a drag was made. //-------------------------------------------------------------------// BOOL OleListCtrl::BeginDrag( int nUnderCursor, UINT nKeyFlags ) { // Attempt a drag. ///////////////////////////////////////////////////// // Next, we provide a ClipFormat holding the item reference. // Make sure ClipFormat is ready to go. ASSERT( ClipFormat != NULL ); // Dump the current selection into drag data array. ExtractItemsToDragData( true, nUnderCursor ); // To drag, we need a COleDataSource that is loaded with our data. // Get a new one. COleDataSource DataSource; // Put the drag data into the DS. ArchiveAndRenderClipFormats( &DataSource ); // Now we can clear the previous drag contents. Items.RemoveAll(); // ///////////////////////////////////////////////////// // Get the rectangle of the list item. // This will help us avoid a drag unless the user really means it. CRect ItemRect; GetItemRect( nUnderCursor, &ItemRect, LVIR_BOUNDS ); ClientToScreen( &ItemRect ); // Set flags to indicate that we are dragging. nListItemBeingDragged = nUnderCursor; bDraggingFromThisList = true; // Now drag it. DROPEFFECT deResult = DataSource.DoDragDrop( DROPEFFECT_COPY | DROPEFFECT_MOVE, // | DROPEFFECT_LINK, ItemRect ); InsertStart(); // Indicate that we are no longer dragging. bDraggingFromThisList = false; nListItemBeingDragged = -1; // If it was a move, remove the item(s). if ( deResult == DROPEFFECT_MOVE ) { // Delete the current selection, then // highlight the dragged items. DeleteOldAndHighlightNew(); } // Successful drag and drop operation. if ( deResult != DROPEFFECT_NONE ) { // Allow derived classes to do any additional clean up steps. FinishDragAndDrop(); } InsertEnd(); return ( deResult != DROPEFFECT_NONE ); }