コード例 #1
0
int main(void)
{
	HashTable ht = newTable(SIZE);
	
	insertItem(ht, "Friend"); // insert items into ht
	insertItem(ht, "Yolo");
	insertItem(ht, "Lookin fors for the holidays"); 

	showHashTable(ht);
	removeItem(ht, "Friend"); // remove item in ht
	removeItem(ht, "asbdfb"); // remove item not in ht
	showHashTable(ht);

	insertItem(ht, "Matthew");
	insertItem(ht, "Matthew"); // collision
	showHashTable(ht);

	Item *it = searchItem(ht, "Matthew"); // search for item in ht
	assert(it != NULL);
	
	it = searchItem(ht, "friend"); // search for item not in ht
	assert(it == NULL);
	printf("it = %p\n", it);
		
	ht = hashTableExpand(ht, 30);
	showHashTable(ht);

	disposeTable(ht);
	return EXIT_SUCCESS;
}
コード例 #2
0
ファイル: qdjviewsidebar.cpp プロジェクト: Distrotech/djview4
void 
QDjViewOutline::pageChanged(int pageno)
{
  int fp = -1;
  QTreeWidgetItem *fi = 0;
  // find current selection
  QList<QTreeWidgetItem*> sel = tree->selectedItems();
  QTreeWidgetItem *si = 0;
  if (sel.size() == 1)
    si = sel[0];
  // current selection has priority
  if (si)
    searchItem(si, pageno, fi, fp);
  // search
  for (int i=0; i<tree->topLevelItemCount(); i++)
    searchItem(tree->topLevelItem(i), pageno, fi, fp);
  // select
  if (si && fi && si != fi)
    tree->setItemSelected(si, false);
  if (fi && si != fi)
    {
      tree->setCurrentItem(fi);
      tree->setItemSelected(fi, true);
      tree->scrollToItem(fi);
    }
}
コード例 #3
0
ファイル: bin_src.cpp プロジェクト: VIU7-51/abracadabra
int Array::searchItem(int left, int right, int src) {
  if (left > right) exit(EXIT_FAILURE);  //первое необходимое условие - левые границы должны быть меньше правых на входе в функцию
  int median  = (left + right) / 2; //создаем индекс для среднего элемента массива
  if (arr[median] == src) return arr[median]; //сравниваем элемент с запросом поиска
  if(left == right) exit(EXIT_FAILURE); //второе необходимое условие - после ненахождения среднего элемента
                                        //границы не должны быть установлены на одном значении
  if (src < arr[median]) return searchItem(left, median - 1, src); //вызов рекурсивной функции поиска
                                                                   //при условии что искомый элемент меньше серединного
  else return searchItem(median + 1, right, src); //иначе вызов с противоположным условием
}
コード例 #4
0
ファイル: BinarySearchTree.cpp プロジェクト: Prithula/Test
struct treeNode * searchItem(struct treeNode * node, int item)
{
    if(node==0) return 0;
    if(node->item==item) return node; //found, return node
    struct treeNode * t = 0;
    if(item < node->item)
        t = searchItem(node->left, item); //search in the left sub-tree
    else
        t = searchItem(node->right, item); //search in the right sub-tree
    return t;
};
コード例 #5
0
void ArrayList::removeItem(int item)
{
	int position;
	position = searchItem(item) ;
	if ( position == NULL_VALUE ) return ; //nothing to remove
	removeItemAt(position) ;
}
コード例 #6
0
ファイル: searchbox.cpp プロジェクト: miyabi-satoh/Gefu
void SearchBox::keyPressEvent(QKeyEvent *event)
{
#if 0
    QString ksq = KeyEventToSequence(event);

    if (ksq == "/") {
        QAction *action = getMainWnd()->findChild<QAction*>("action_Search");
        action->toggle();
        event->accept();
        return;
    }

    QString textBefore = text();
    QLineEdit::keyPressEvent(event);


    if (ksq == "Shift+Return"){
        qDebug() << ksq;
        emit getMainWnd()->findChild<QAction*>("action_SearchPrev")->triggered();
    }
    else if (ksq.indexOf("Return") != -1) {
        qDebug() << ksq;
        emit getMainWnd()->findChild<QAction*>("action_SearchNext")->triggered();
    }
    else if (textBefore != text()) {
        emit searchItem(text());
    }
    else {
        qDebug() << ksq;
    }
#endif

    QLineEdit::keyPressEvent(event);

}
コード例 #7
0
ファイル: main.c プロジェクト: zezulka/antiRot
bool performCommand(char command, item* it)
{
    FILE* f = fopen(ITEMLIST, "a+");
    assert(f != NULL);
    switch(command)
    {
        case'r':
            {
                deleteItem(f, it);
                fclose(f);
            } //remove command
        case 'd': //this part of display is the same as for the remove part
                f = fopen(ITEMLIST, "r");
                display(f);
                break;
        case'a':
            {
                addItem(f, it);
                display(f);
                break;
            } //add command
        case's':
            {
                searchItem(f, it);
                break;
            } //search command
        default:
            {
                break;
            }
    }
    fclose(f);
    return true;
}
コード例 #8
0
ファイル: BinarySearchTree.cpp プロジェクト: Prithula/Test
int calcHeight(int item) //return height of an item in the tree
{
    struct treeNode * node = 0;
    node = searchItem(root, item);
    if(node==0) return -1; //not found
    else return calcNodeHeight(node);
}
コード例 #9
0
ファイル: publicMenu.cpp プロジェクト: CSI-240-2016/Inventory
void displaySearchMenu(LinkedList<Item> *listOfItems, LinkedList<Club> *listOfClubs, LinkedList<User> *listOfUsers)
{
	int choice = 0;

	clearScreen();
	displayLogo();

	cout << setw(22) << right << "Search Menu:\n\n\n";
	cout << setw(12) << right << "1.) " << left << "Search for a Club\n";
	cout << setw(12) << right << "2.) " << left << "Search for an Item\n";
	cout << setw(12) << right << "3.) " << left << "Return to Menu\n";
	
	string junk;
	do {
		cout << setw(28) << right << "Please enter a choice: ";
		cin >> choice;
		getline(cin, junk); // get rid of anything else in the line
		if (choice < 1 || choice > 3)
			cout << setw(28) << right << "Invalid...\n";
	} while (choice < 1 || choice > 3);

	switch (choice)
	{
	case 1:
		searchClub(listOfItems);
		break;
	case 2:
		searchItem(listOfItems);
		break;
	case 3:
		displayGeneralMenu(listOfItems, listOfClubs, listOfUsers);
	}
}
コード例 #10
0
int main(void)
{
    initializeTree();
    while(1)
    {
        printf("1. Insert item. 2. Delete item. 3. Search item. \n");
        printf("4. Print height of tree. 5. Print height of an item. \n");
        printf("6. PrintInOrder. 7. Range Search.\n");

        int ch;
        scanf("%d",&ch);
        if(ch==1)
        {
            int item;
            scanf("%d", &item);
            insertItem(root, item);
        }
        else if(ch==2)
        {
            int item;
            scanf("%d", &item);
            deleteItem(root, item);
        }
        else if(ch==3)
        {
            int item;
            scanf("%d", &item);
            struct treeNode * res = searchItem(root, item);
            if(res!=0) printf("Found.\n");
            else printf("Not found.\n");
        }
        else if(ch==4)
        {
            int height = calcNodeHeight(root);
            printf("Height of tree = %d\n", height);
        }
        else if(ch==5)
        {
            int item;
            scanf("%d", &item);
            int height = calcHeight(item);
            printf("Height of %d = %d\n", item, height);
        }
        else if(ch==6)
        {
            int h = calcNodeHeight(root);
            printf("\n--------------------------------\n");
            printInOrder(root, h);
            printf("--------------------------------\n");
        }
        else if(ch==7)
        {
            int l,r;
            scanf("%d%d",&l,&r);
            printf("%d\n",rangeSearch(root,l,r));
        }
    }

}
コード例 #11
0
ファイル: Homework.cpp プロジェクト: rifatarefin/git_project
int deleteItem(int item)
{
    int position;
    position = searchItem(item) ;
    if ( position == NULL_VALUE ) return NULL_VALUE;
    deleteItemAt(position) ;
    return SUCCESS_VALUE ;
}
コード例 #12
0
int calcDepth(int item)
{
    struct treeNode *temp;
    temp=searchItem(root,item);
    if (temp==0) return FALSE_VALUE;
    else return calcNodeDepth(temp);

}
コード例 #13
0
ファイル: el_main.c プロジェクト: gerrarddejonge/el-calc
int main(int argc, char * argv[])
{
	struct PState pstate = {"Unknown", 1, false, "", false, -1};
	struct List itemlist = {NULL, NULL};
	struct ShoppingCart cart = {NULL, NULL};
	char path[PATHSIZE];
	struct Item * temp;
	
//	printf("Pstate->name: %s, Pstate->amount: %d\n", pstate.itemname, pstate.amount);
	if (argc > 1) {
		get_args(argc, argv, &pstate);
		getFilePath(path, &pstate);
		
		if (loadAllItems(&itemlist, path) == EL_FAIL) {
			printf("Could not read the items.\n");
			exit(EXIT_FAILURE);
		}
		
		if (pstate.itemid >= 0) {
			if (( temp = findItemId(itemlist.head, pstate.itemid)) != NULL) {
				strcpy(pstate.itemname, temp->name);
			}
		}

/// If we have a lookup or search request, execute it and exit program
		if (pstate.search) {
			printf("Searching for %s.\n", pstate.itemname);
			searchItem(&itemlist, pstate.itemname);
			freeItemList(&itemlist);
			exit(EXIT_SUCCESS);
		} else if (pstate.lookup) {
			printf("Looking for %s.\n", pstate.itemname);
			lookup(&itemlist, pstate.itemname);
			freeItemList(&itemlist);
			exit(EXIT_SUCCESS);
		}
		
		printf("\nCalculations for %d %s\n\n", pstate.amount, pstate.itemname);
		
		printf("Filling shopping cart.\n\n");
		
		if (buildShoppingList(&itemlist, &cart, pstate.itemname, pstate.amount) == EL_FAIL) {
			printf("Failure to build shopping list.\n");
			exit(EXIT_FAILURE);
		}
		
		printf("\n\nTotals for %d %s\n\n", pstate.amount, pstate.itemname);
		
		printShoppingList(cart.head);
		
		freeItemList(&itemlist);
		freeCart(&cart);
	} else {
		printf("\nMissing parameters. \nUse: \n\t%s --help\nfor correct syntax\n\n", argv[0]);
	}
	
	return 0;
}
コード例 #14
0
void SettingsPageUnits::load()
{
  GeneralConfig *conf = GeneralConfig::instance();

  UnitAlt->setCurrentIndex(searchItem(altitudes, conf->getUnitAlt(), UnitAlt->count()));
  UnitDistance->setCurrentIndex(searchItem(distances, conf->getUnitDist(), UnitDistance->count()));
  UnitSpeed->setCurrentIndex(searchItem(speeds, conf->getUnitSpeed(), UnitSpeed->count()));
  UnitVario->setCurrentIndex(searchItem(varios, conf->getUnitVario(), UnitVario->count()));
  UnitWind->setCurrentIndex(searchItem(winds, conf->getUnitWind(), UnitWind->count()));
  UnitPosition->setCurrentIndex(searchItem(positions, conf->getUnitPos(), UnitPosition->count()));
  UnitTime->setCurrentIndex(searchItem(times, conf->getUnitTime(), UnitTime->count()));
  UnitTemperature->setCurrentIndex(searchItem(temperature, conf->getUnitTemperature(), UnitTemperature->count()));
  UnitAirPressure->setCurrentIndex(searchItem(airPressure, conf->getUnitAirPressure(), UnitAirPressure->count()));
}
コード例 #15
0
int calcDepth(int item)//return depth of an item in the tree
{
    //write your codes here
    struct treeNode * node = 0;
    node = searchItem(root, item);

    return calcNodeDepth(node);

}
コード例 #16
0
int main(void)
{
    initializeList();
    while(1)
    {
        printf("1. Insert new item. 2. Delete item. 3. Search item. \n");
        printf("4. Insert Last. 5. Delete Last. 6. Print forward. \n");
        printf("7. Print backward. 8. exit.\n");

        int ch;
        scanf("%d",&ch);
        if(ch==1)
        {
            int item;
            scanf("%d", &item);
            insertFirst(item);
        }
        else if(ch==2)
        {
            int item = deleteLast();
            if(item!=NULL_VALUE) printf("Deleted: %d\n", item);
        }
        else if(ch==3)
        {
            int item;
            scanf("%d", &item);
            struct listNode * res = searchItem(item);
            if(res!=0) printf("Found.\n");
            else printf("Not found.\n");
        }
        else if(ch==4)
        {
            int item;
            scanf("%d",&item);
            insertLast(item);
        }
        else if(ch==5)
        {
            deleteLast();
        }
        else if(ch==6)
        {
            printListForward();
        }
        else if(ch==7)
        {
            printListBackward();
        }
        else if(ch==8)
        {
            freeall(list);
            break;
        }
    }

}
コード例 #17
0
ファイル: hrc_taskqueue.c プロジェクト: EffyLiu0301/lpel
/*
 * Update priority for a task in the queue
 */
void LpelTaskqueueUpdatePriority(taskqueue_t *tq, lpel_task_t *t, double np){
	int pos = searchItem(tq, t);
	assert(pos > 0);
	double p = t->sched_info.prior;
	t->sched_info.prior = np;
	if (np > p)
		upHeap(tq, pos);
	else if (np < p)
		downHeap(tq, pos);
}
コード例 #18
0
ファイル: asyncServer.c プロジェクト: timburrow/ovj3
int
registerAsyncIO( int fd, void (*program)() )
{
	AIOE		thisEntry;

	if (pRegisterAsync == NULL) {
		registerAsyncHandlers(
			SIGIO,
			sigio_irpt,
			processIOEntry
		);
	}

	thisEntry = (AIOE) malloc( sizeof( struct async_io_entry ) );
	if (thisEntry == NULL)
	  return( -1 );

	thisEntry->fd = fd;
	thisEntry->program = program;

/*  If there is no entry with this file descriptor, then add thisEntry to the list.
    If there is an entry, test if the associated programs are identical.  If not,
    delete the old entry and append the new entry.  (No action required if the old
    entry references the same program as the one referenced in the argument list.)

    You can just use the free program directly as the destructor.  See deleteEntry.	*/

	if (searchItem( pRegisterAsync, thisEntry, cmp_fd ) < 0) {
		pRegisterAsync = appendItem( pRegisterAsync, thisEntry );
	}
	else {
		if (searchItem( pRegisterAsync, thisEntry, cmp_async_io_entry ) >= 0)
		  return( 0 );

		pRegisterAsync = deleteItem( pRegisterAsync, thisEntry, cmp_fd, free );
		pRegisterAsync = appendItem( pRegisterAsync, thisEntry );
	}
}
コード例 #19
0
int main(void)
{
    initializeList();
    while(1)
    {
        printf("1. Insert new item. 2. Delete item. 3. Search item.  \n");
        printf("4. Insert last.     5. Print.       6.exit. \n");

        int ch;
        scanf("%d",&ch);
        if(ch==1)
        {
            int item;
            scanf("%d", &item);
            insertItem(item);
        }
        else if(ch==2)
        {
            int item;
            scanf("%d", &item);
            deleteItem(item);
        }
        else if(ch==3)
        {
            int item;
            scanf("%d", &item);
            struct listNode * res = searchItem(item);
            if(res!=0) printf("Found.\n");
            else printf("Not found.\n");
        }
        else if(ch==4)
        {
            int item;
            scanf("%d", &item);
            insertLast(item);
        }
        else if(ch==5)
        {
            printList();
        }

        else if(ch==6)
        {
            break;
        }

    }

}
コード例 #20
0
int insertAfter(int oldItem, int newItem)
{
    //write your codes here
    listNodes *temp,*newNode;
    temp=searchItem (oldItem);
    if(temp==0)return NULL_VALUE;
    else
    {
        newNode=(listNodes*)malloc(sizeof(listNodes));
        newNode->item=newItem;
        newNode->next=temp->next;
        temp->next=newNode;
    }
    return SUCCESS_VALUE;
}
コード例 #21
0
ファイル: qdjviewsidebar.cpp プロジェクト: Distrotech/djview4
void 
QDjViewOutline::searchItem(QTreeWidgetItem *item, int pageno, 
                           QTreeWidgetItem *&fi, int &fp)
{
  QVariant data = item->data(0, Qt::UserRole);
  if (data.type() == QVariant::Int)
    {
      int page = data.toInt();
      if (page>=0 && page<=pageno && page>fp)
        {
          fi = item;
          fp = page;
        }
    }
  for (int i=0; i<item->childCount(); i++)
    searchItem(item->child(i), pageno, fi, fp);
}
コード例 #22
0
ファイル: asyncServer.c プロジェクト: timburrow/ovj3
static void
processIOEntry( int fd )
{
	int	sequence;
	AIOE	searcher, found;

	searcher = (AIOE) malloc( sizeof( struct async_io_entry ) );
	searcher->fd = fd;
	searcher->program = NULL;

	sequence = searchItem( pRegisterAsync, searcher, cmp_fd );
	if (sequence < 0) {
		fprintf( stderr, "no entry found for f/d %d\n", fd );
		return;
	}
	found = (AIOE) getItem( pRegisterAsync, sequence );
	if (found == NULL || found->program == NULL) {
		fprintf( stderr, "no program for f/d %d\n", fd );
		return;
	}

	(*((found)->program))( fd );
	return;
}
コード例 #23
0
ファイル: adminMenu.cpp プロジェクト: CSI-240-2016/Inventory
void displayAdminSearch(LinkedList<Item> *listOfItems, LinkedList<Club> *listOfClubs, LinkedList<User> *listOfUsers)
{
	int choice = 0;
	string junk;

	clearScreen();
	displayLogo();

	cout << setw(22) << right << "Search Menu:\n\n\n";
	cout << setw(12) << right << "1.) " << left << "Search for a Club\n";
	cout << setw(12) << right << "2.) " << left << "Search for an Item\n";
	cout << setw(12) << right << "3.) " << left << "Return to Administrator Menu\n";

	cout << setw(28) << right << "Please enter a choice: ";
	cin >> choice;
	getline(cin, junk);

	while ((choice < 1) || (choice > 3))
	{
		cout << setw(28) << right << "Invalid... Enter choice: ";
		cin >> choice;
		getline(cin, junk);
	}

	switch (choice)
	{
	case 1:
		searchClub(listOfItems);
		break;
	case 2:
		searchItem(listOfItems);
		break;
	case 3:
		displayAdminMenu(listOfItems, listOfClubs, listOfUsers);
	}
}
コード例 #24
0
Tracker::Tracker(QWidget *parent)
    : QWidget(parent)
{
 //****************construct putton and widget************************//
    //Calendar Setting
    calendar = new QCalendarWidget;
    calendar->setGridVisible(true);

    QLabel *listname=new QLabel("                   Detail  Table");
    listname->setFont(QFont("Times", 16, QFont::Bold));

    listname->setStyleSheet("QLabel { background-color : rgb(255, 165, 0); color : black; }");
    detailList=new QListWidget;
    detailList->setStyleSheet( "QListWidget::item { background-color: white;border-bottom: 1px solid black; }"
                                  "QListWidget::item:selected{color: #333538;background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 #cdcdcd, stop: 1 #ababab); border-top: 1px solid;border-top-color: #a8abad;border-bottom: 1px solid;border-bottom-color: #bfc7ce;}");

    removeButton=new QPushButton(tr("&REMOVE"));
    removeButton->setFont(QFont("Cambria", 14, QFont::Bold));
    QVBoxLayout *LayoutRight=new QVBoxLayout;
    LayoutRight->addWidget(listname,1);
    LayoutRight->addWidget(detailList,12);
    LayoutRight->setSpacing(3);
    LayoutRight->addWidget(removeButton,2);

    QHBoxLayout *Layout1=new QHBoxLayout;
    Layout1->addWidget(calendar,3);
    Layout1->addLayout(LayoutRight,2);

//Background Setting

    QString newpath (":/image/images/2.jpg");
    QPixmap pixmap = QPixmap(newpath).scaled(this->size());
    QPalette palette(this->palette());
    palette.setBrush(QPalette::Background, QBrush(pixmap));
    this->setPalette(palette);

//pushbutton declaration
    addExpenseButton = new QPushButton(tr("&Expense"));
    addExpenseButton->setFont(QFont("Cambria", 13, QFont::Bold));
    addIncomeButton= new QPushButton(tr("&Income"));
    addIncomeButton->setFont(QFont("Cambria", 13, QFont::Bold));
    shoppingListButton= new QPushButton(tr("&Shopping List"));
    shoppingListButton->setFont(QFont("Cambria", 13, QFont::Bold));
    reportButton = new QPushButton(tr("&Report"));
    reportButton->setFont(QFont("Cambria", 13, QFont::Bold));
    searchButton = new QPushButton(tr("&Search"));
    searchButton->setFont(QFont("Cambria", 13, QFont::Bold));
    searchLine = new QLineEdit;

    // Button horizontal layout
    QHBoxLayout *buttonLayout1 = new QHBoxLayout;
    buttonLayout1->addWidget(addExpenseButton,1);
    buttonLayout1->addWidget(addIncomeButton,1);
    buttonLayout1->addWidget(reportButton,1);
    buttonLayout1->addWidget(shoppingListButton,1);


    QHBoxLayout *searcharea = new QHBoxLayout;
    searcharea->addWidget(searchLine,3);
    searcharea->addWidget(searchButton,1);

    QVBoxLayout *left = new QVBoxLayout;
    left->addLayout(buttonLayout1);
    left->addLayout(searcharea);
   //right area

    settingbudget=new QPushButton(tr("Monthly Budget"));
    settingbudget->setFont(QFont("Times", 15, QFont::Bold));

    budget=new QLCDNumber;
    budget->setSegmentStyle(QLCDNumber::Filled);
    //budget->display(budgetAmount);

    QPushButton *ratiobar=new QPushButton(tr("Expense Ratio"));
    ratiobar->setFont(QFont("Times", 15, QFont::Bold));
    ratio=new QProgressBar;


   QGridLayout *showarea=new QGridLayout;
   showarea->setSpacing(20);
   showarea->addWidget(settingbudget,0,0);
   showarea->addWidget(budget,0,1);
   showarea->addWidget(ratiobar,1,0);
   showarea->addWidget(ratio,1,1);

   QHBoxLayout *Layout2=new QHBoxLayout;
   Layout2->addLayout(left,3);
   Layout2->addLayout(showarea,2);

   QVBoxLayout *mainLayout=new QVBoxLayout;
   mainLayout->addLayout(Layout1,10);
   mainLayout->addLayout(Layout2,3);
   setLayout(mainLayout);
   setWindowTitle("Basic Model");

//! [grid layout]
    setLayout(mainLayout);
    setWindowTitle(tr("Basic Model"));
    
//****************construct items and labels************************//
    
//        QDir currentDir;
//        QString path = currentDir.currentPath();
//    QString filePathE = path + "/../../../expense_data.csv";
//    QString filePathI = path + "/../../../income_data.csv";
//    QString filePathEL = path + "/../../../expense_labels.txt";
//    QString filePathIL = path + "/../../../income_labels.txt";
    QString homePath = QString(getenv("HOME"));
    //std::cout<<homePath.toStdString().c_str()<<std::endl;

    QDir *temp = new QDir;
    bool exist = temp->exists(homePath + "/.ExpenseTracker_withData");
    if(exist == 0)   temp->mkdir(homePath + "/.ExpenseTracker_withData");

    QString filePathE = homePath + "/.ExpenseTracker_withData/expense_data.csv";
    QString filePathI = homePath + "/.ExpenseTracker_withData/income_data.csv";
    QString filePathEL = homePath + "/.ExpenseTracker_withData/expense_labels.txt";
    QString filePathIL = homePath + "/.ExpenseTracker_withData/income_labels.txt";
    QString filePathB = homePath + "/.ExpenseTracker_withData/budget.txt";
    QString filePathSL = homePath + "/.ExpenseTracker_withData/shoppingList.csv";



    std::ifstream fin(filePathE.toStdString().c_str());
    if(!fin){

        QString dataPath (":/data/resource");
        QString filePathEd = dataPath + "/expense_data.csv";
        QString filePathId = dataPath + "/income_data.csv";
        QString filePathELd = dataPath + "/expense_labels.txt";
        QString filePathILd = dataPath + "/income_labels.txt";
        QString filePathBd = dataPath + "/budget.txt";
        QString filePathSLd = dataPath + "/shoppingList.csv";


        expenseItems = readData(filePathEd);
        incomeItems = readData(filePathId);
        expenseLabels = readLabel(filePathELd);
        incomeLabels = readLabel(filePathILd);
        budgetAmount = readBudget(filePathBd);
        shoppingItems = readShoppingList(filePathSLd);
        writeData(expenseItems, filePathE.toStdString().c_str());
        writeData(incomeItems, filePathI.toStdString().c_str());
        writeLabel(expenseLabels, filePathEL.toStdString().c_str());
        writeLabel(incomeLabels, filePathIL.toStdString().c_str());
        writeBudget(budgetAmount, filePathB.toStdString().c_str());
        writeShoppingList(shoppingItems, filePathSL.toStdString().c_str());


    }
    else{
        expenseItems = readData(filePathE.toStdString().c_str());
        incomeItems = readData(filePathI.toStdString().c_str());
        expenseLabels = readLabel(filePathEL.toStdString().c_str());
        incomeLabels = readLabel(filePathIL.toStdString().c_str());
        budgetAmount = readBudget(filePathB.toStdString().c_str());
        std::ifstream finSL(filePathSL.toStdString().c_str());
        if(finSL){
            shoppingItems = readShoppingList(filePathSL.toStdString().c_str());
        }
        else{
            shoppingItems = NULL;
        }
    }
    budget->display(budgetAmount);
    selectedDateChanged();
    double ratioValue = report_sum_M(QDate::currentDate().month(),QDate::currentDate().year(),expenseItems)/budgetAmount;
    if(ratioValue < 1){
       ratio->setValue(100*ratioValue);
    }
    else ratio->setValue(100);
    searchFlag = 0;
//******************connecting signals and slots***************************//
    connect(addExpenseButton, SIGNAL(clicked()), this, SLOT(addexpensewindow()));
    connect(addIncomeButton, SIGNAL(clicked()), this, SLOT(addincomewindow()));
    connect(reportButton, SIGNAL(clicked()), this, SLOT(report()));
    connect(calendar, SIGNAL(selectionChanged()), this, SLOT(selectedDateChanged()));
    connect(settingbudget, SIGNAL(clicked()), this, SLOT(settingBudget()));
    connect(removeButton, SIGNAL(clicked()), this, SLOT(removeItem()));
    connect(shoppingListButton, SIGNAL(clicked()), this, SLOT(checkShoppingList()));
    connect(searchButton, SIGNAL(clicked()), this, SLOT(searchItem()));
    connect(searchLine, SIGNAL(returnPressed()), this, SLOT(searchItem()));
}
コード例 #25
0
int main(void)
{
    //freopen("in2.txt", "r", stdin);
    initializeTree();
    while(1)
    {
        //printMenu();
        int ch;
        scanf("%d",&ch);
        if(ch == 1)
        {
            int item;
            scanf("%d", &item);
            insertItem(root, item);
        }
        else if(ch == 2)
        {
            int item;
            scanf("%d", &item);
            deleteItem(root, item);
        }
        else if(ch == 3)
        {
            int item;
            scanf("%d", &item);
            struct treeNode * res = searchItem(root, item);
            if(res!=0) printf("Found.\n");
            else printf("Not found.\n");
        }
        else if(ch == 4)
        {
            int height = calcNodeHeight(root);
            printf("Height of tree = %d\n", height);
        }
        else if(ch == 5)
        {
            int item;
            scanf("%d", &item);
            int height = calcHeight(item);
            printf("Height of %d = %d\n", item, height);
        }
        else if(ch == 6)
        {
            int h = calcNodeHeight(root);
            printf("\n--------------------------------\n");
            printInOrder(root, h);
            printf("--------------------------------\n");
        }
        else if(ch == 7)
        {
            printf("%d\n", getSize(root));
        }
        else if(ch == 8)
        {
            int item;
            scanf("%d", &item);
            printf("%d\n", calcDepth(item));
        }
        else if(ch == 9)
        {
            printf("%d\n", calcNodeDepth(root));
        }
        else if(ch == 10)
        {
            if(root == 0) {
                printf("tree is empty\n");
                continue;
            }
            printf("%d\n", getMinItem());
        }
        else if(ch == 11)
        {
            if(root == 0) {
                printf("tree is empty\n");
                continue;
            }
            printf("%d\n", getMaxItem());
        }
        else if(ch == 12)
        {
            int left, right;
            scanf("%d %d", &left, &right);
            printf("%d\n", rangeSearch(root, left, right));
        }
        else if(ch == 13)
        {
            int item;
            scanf("%d", &item);
            //printf("Del : %d\n", item);
            //deleteItem(root, item);
            printf("%d\n", deleteItem(root, item));
        }
        else if(ch == 14)
        {
            break;
        }
    }

}
コード例 #26
0
int deleteItem(struct treeNode * node, int item)
{
    //write your code here, return TRUE, FALSE
    if(node!=0)
    {
        struct treeNode *target=searchItem(node,item);
        if(node==target)
        {
            if((target->left==0)&&(target->right==0))//  no children
            {
                free(target);
                root=0;
                return TRUE_VALUE;
            }
            else if(target->left==0)//right
            {
                root=target->right;
                free(target);
                return TRUE_VALUE;
            }
            else if(target->right==0)//left
            {
                root=target->left;
                free(target);
                return TRUE_VALUE;
            }
            else// left right both
            {
                struct treeNode *prev,*temp,*prev1;
                temp=target->right;
                for(;temp!=0;)//replacer
                {
                    prev=temp;
                    temp=temp->left;
                }
                if(prev==target->right)// if replacer is the immediate right of target
                {
                    target->item=prev->item;
                    target->right=prev->right;// target is following replacer s child
                    free(target->right);
                    return TRUE_VALUE;
                }
                temp=target->right;
                for(;temp!=prev;)// parent of replacer
                {
                    prev1=temp;
                    temp=temp->left;
                }
                target->item=prev->item;// replacing
                prev1->left=prev->right;// parent of replacer is following replacer s child
                //free(target);//freeing
                //prev1->left=0;

                return TRUE_VALUE;

            }
        }
        else//not root node
        {
            struct treeNode *temp=root,*prev=0;
            for(;(temp!=0)&&(temp->item!=item);)//searching parent of target
            {
                prev=temp;
                if(temp->item>item)
                {
                    temp=temp->left;
                }
                else if(temp->item<item)
                {
                    temp=temp->right;
                }
            }
            if((target->left==0)&&(target->right==0))//  no children
            {
                //free(target);
                //root=0;

                if(prev->left==target)
                {
                    free(prev->left);
                    prev->left=0;

                }
                else if(prev->right==target)
                {
                    free(target);
                    prev->right=0;
                }
                return TRUE_VALUE;

            }
            else if(target->left==0)//right
            {
                /*target=target->right->item;
                free(target->right);
                target->right=0;
                return TRUE_VALUE;*/
                if(prev->left==target)
                {
                    prev->left=target->right;
                    free((target));
                    return TRUE_VALUE;

                }
                else if(prev->right==target)
                {
                    prev->right=target->right;
                    free((target));
                    return TRUE_VALUE;
                }

            }
            else if(target->right==0)//left
            {
                if(prev->left==target)
                {
                    prev->left=target->left;
                    free((target));
                    return TRUE_VALUE;

                }
                else if(prev->right==target)
                {
                    prev->right=target->left;
                    free((target));
                    return TRUE_VALUE;
                }
            }
            else// left right both
            {
                struct treeNode *prev,*temp,*prev1;
                temp=target->right;
                for(;temp!=0;)//replacer
                {
                    prev=temp;
                    temp=temp->left;
                }
                if(prev==target->right)// if replacer is the immediate right of target
                {
                    target->item=prev->item;
                    target->right=prev->right;// target is following replacer s child
                    free(prev);
                    return TRUE_VALUE;
                }
                temp=target->right;
                for(;temp!=prev;)// parent of replacer
                {
                    prev1=temp;
                    temp=temp->left;
                }
                target->item=prev->item;// replacing
                prev1->left=prev->right;// parent of replacer is following replacer s child
                //free(target);//freeing
                //prev1->left=0;
                return TRUE_VALUE;

            }
        }
    }
    else
    {
        return FALSE_VALUE;
    }

}
コード例 #27
0
int main(void)
{
    initializeList();
    while(1)
    {
        printf("1. Insert new item. 2. Delete item. 3. Search item. \n");
        printf("4. Insert new item at last of list. 5. Insert new item after old item in list.\n");
        printf("6. Delete first item in list 7. Delete last item in list.\n");
        printf("8. Print. 9. exit.\n");



        int ch;
        scanf("%d",&ch);
        if(ch==1)
        {
            int item;
            scanf("%d", &item);
            insertItem(item);
        }
        else if(ch==2)
        {
            int item;
            scanf("%d", &item);
            deleteItem(item);
        }
        else if(ch==3)
        {
            int item;
            scanf("%d", &item);
            struct listNode * res = searchItem(item);
            if(res!=0) printf("Found.\n");
            else printf("Not found.\n");
        }
        else if(ch==4)
        {
            int item;
            scanf("%d",&item);
            insertLast(item);
        }
        else if(ch==5)
        {
            int oldItem,newItem;
            printf("Old item: ");
            scanf("%d",&oldItem);
            printf("New item: ");
            scanf("%d",&newItem);
            insertAfter(oldItem,newItem);
        }
        else if(ch==6)
        {
            deleteFirst();
        }
        else if(ch==7)
        {
            deleteLast();
        }
        else if(ch==8)
        {
            printList();
        }
        else if(ch==9)
        {
            break;
        }
    }

}
コード例 #28
0
int main(void)
{
    initializeTree();
    while(1)
    {
        printf("\n1. Insert item. 2. Delete item. 3. Search item. \n");
        printf("4. Print height of tree. 5. Print height of an item. \n");
        printf("6. PrintInOrder. 7. Calculate Depth 8. get MinItem. 9. get MaxItem.\n10. Range search. 11. Delete. 12. exit.\n");

        int ch;
        scanf("%d",&ch);
        if(ch==1)
        {
            int item;
            scanf("%d", &item);
            insertItem(root, item);
        }
        else if(ch==2)
        {
            int item;
            scanf("%d", &item);
            deleteItem(root, item);
        }
        else if(ch==3)
        {
            int item;
            scanf("%d", &item);
            struct treeNode * res = searchItem(root, item);
            if(res!=0) printf("Found.\n");
            else printf("Not found.\n");
        }
        else if(ch==4)
        {
            int height = calcNodeHeight(root);
            printf("Height of tree = %d\n", height);
        }
        else if(ch==5)
        {
            int item;
            scanf("%d", &item);
            int height = calcHeight(item);
            printf("Height of %d = %d\n", item, height);
        }
        else if(ch==6)
        {
            int h = calcNodeHeight(root);
            printf("\n--------------------------------\n");
            printInOrder(root, h);
            printf("--------------------------------\n");
        }
        else if(ch==12)
        {
            break;
        }
        else if(ch==7)
        {
            int i;
            scanf("%d",&i);
            printf("depth %d\n",calcDepth(i));
        }


        else if(ch==8)
        {
            printf("min item %d\n",getMinItem());
        }
        else if(ch==9)
        {
            printf("max item %d\n",getMaxItem());
        }
        else if(ch==10)
        {
            int item1,item2;
            scanf("%d%d", &item1,&item2);
            printf("Item number %d",rangeSearch(root,item1,item2));

        }
        else if(ch==11)
        {
            int a;
            scanf("%d",&a);
            deleteItem(root,a);
        }
    }

}