Exemplo n.º 1
0
int PixmapCacheModel::updateCacheCount(int lastCacheSizeEvent,
        qint64 pixmapStartTime, qint64 pixSize, PixmapCacheItem &newEvent, int typeId)
{
    newEvent.pixmapEventType = PixmapCacheCountChanged;
    newEvent.rowNumberCollapsed = 1;
    newEvent.typeId = typeId;

    int index = lastCacheSizeEvent;
    if (lastCacheSizeEvent != -1) {
        newEvent.cacheSize = m_data[lastCacheSizeEvent].cacheSize + pixSize;
        qint64 duration = pixmapStartTime - startTime(lastCacheSizeEvent);
        if (duration > 0) {
            insertEnd(lastCacheSizeEvent, duration);
            index = insertStart(pixmapStartTime, 0);
            m_data.insert(index, newEvent);
        } else {
            // If the timestamps are the same, just replace it
            m_data[index] = newEvent;
        }
    } else {
        newEvent.cacheSize = pixSize;
        index = insertStart(pixmapStartTime, 0);
        m_data.insert(index, newEvent);
    }

    return index;
}
void Draft::pick(Team &user, vector<NodeData*>& a, WINDOW **board, const int &pickN){
	char num[3];
	int rank = 0;
	int temp = pickN;					//for some reason mvwgetstr resets pickN, solved

	nextTen(a, board);

	while(true){
		do{
			mvwprintw(board[32], 1, 1, "Enter rank of desired player(1-300): ");
			wrefresh(board[32]);
			mvwgetstr(board[32], 1, 38, num);
			sscanf(num, "%d", &rank);
		} while(rank < 1 || rank > 300);

		if(!a[rank - 1]->getTaken())
			break;
		else if(a[rank - 1]->getTaken()){
			mvwprintw(board[32], 2, 1, "Already taken, pick again");
			wrefresh(board[32]);
		}
	}

	a[rank - 1]->setTaken(true);
	insertEnd(a[rank - 1]);
	user.roster.add(a[rank - 1], board[31]);
	user.roster.displayRoster(board[31]);
	toBoard(a[rank - 1], board, temp);
}
void Draft::autoP(Team &computer, vector<NodeData*>& a, WINDOW **board, const int &pickN){
	int random = rand() % 100;
	int counter = 0, skipNum = 0;

	usleep(compTime);

	if(random < 60)
		skipNum = 0;
	else if(random >= 60 && random < 80)
		skipNum = 1;
	else if(random >= 80 && random < 90)
		skipNum = 2;
	else if(random >= 90 && random < 97)
		skipNum = 3;
	else if(random >= 97 && random < 100)
		skipNum = 4;

	for(int i = 0; i < a.size(); i++){
		if(!a[i]->getTaken()){									//cur player not taken
			if(counter == skipNum){								//likelyhood counter
				if(computer.roster.hasNeed(a[i])){						//player needed
					a[i]->setTaken(true);							//player taken
					insertEnd(a[i]);								//add to board
					computer.roster.add(a[i], board[31]);			//add to roster
					toBoard(a[i], board, pickN);					
					break;											//complete- exit
				} else continue;									
			}
			else counter++;
		}
	}
}
Exemplo n.º 4
0
void QmlProfilerRangeModel::finalize()
{
    if (!m_stack.isEmpty()) {
        qWarning() << "End times for some events are missing.";
        const qint64 endTime = modelManager()->traceEnd();
        do {
            int index = m_stack.pop();
            insertEnd(index, endTime - startTime(index));
        } while (!m_stack.isEmpty());
    }

    // compute range nesting
    computeNesting();

    // compute nestingLevel - nonexpanded
    computeNestingContracted();

    // compute nestingLevel - expanded
    computeExpandedLevels();

    if (supportsBindingLoops())
        findBindingLoops();

    QmlProfilerTimelineModel::finalize();
}
int main() {
    int max_vertex, max_edge, start, v1, v2, edge, i, v;
    vertex graph;
    if (scanf("%d %d %d", &max_vertex, &max_edge, &start) == 1);
    graph = (vertex) calloc(sizeof(struct vertex), max_vertex);
    for (i = 0; i < max_vertex; i++) {
        graph[i] = newVertex();
    }
    for(i = 0; i < max_edge; i++) {
        if (scanf("%d %d %d", &v1, &v2, &edge) == 1);
        insertEnd(&graph[v1 - 1], newlink(&graph[v2 - 1], edge));
    }
    graph[start - 1].distance = 0;
    graph[start - 1].change = 0;
    BellmanFord(graph, max_vertex);
    for(v = 0; v < max_vertex; v++) {
        if (graph[v].cycle == 1) {
            printf("I\n");
        }
        else if (graph[v].distance == INT_MAX) {
            printf("U\n");
        }
        else {
            printf("%d\n", graph[v].distance);
        }
    }
    return 0;
}
int main(){
	struct node *last = NULL;
	
	insertEmpty(&last,3);
	insertBeginning(&last,1);
	insertEnd(&last,4);
	insertBetween(&last,1,2);
	
	printList(last);
}
Exemplo n.º 7
0
int main()
{
	int d  , o , i , q = 1 ;
	struct Clist *head = NULL ;

	while(q){
		printf("Enter 1 to insert at the begining\nEnter 2 to insert at the end\nEnter 3 to delete at the begining\nEnter 4 to delete at the end\nEnter 5 to print the list\nEnter 6 to exit");
		scanf("%d" , &o) ;

		switch(o)
		{
			case 1 :
			{
				printf("Enter the data : ");
				scanf("%d" , &d) ;
				insertBegin(&head , d) ;
				break ;
			}

			case 2 :
			{
				printf("Enter the data : ");
				scanf("%d" , &d) ;
				insertEnd(&head , d) ;
				break ;
			}

			case 3 :
			{
				deleteStart(&head) ;
				break ;
			}

			case 4 :
			{
				deleteEnd(&head) ;
				break ;
			}

			case 5 :
			{
				display(head) ;
				break ;
			}
		    
		    case 6 :
		    {
		    	q = 0 ;
		    }
		}	
	}

}
Exemplo n.º 8
0
void PixmapCacheModel::finalize()
{
    if (m_lastCacheSizeEvent != -1) {
        insertEnd(m_lastCacheSizeEvent, modelManager()->traceTime()->endTime() -
                  startTime(m_lastCacheSizeEvent));
    }

    resizeUnfinishedLoads();
    computeMaxCacheSize();
    flattenLoads();
    computeNesting();
}
Exemplo n.º 9
0
void PixmapCacheModel::resizeUnfinishedLoads()
{
    // all the unfinished "load start" events continue till the end of the trace
    for (auto pixmap = m_pixmaps.begin(), pixmapsEnd = m_pixmaps.end();
         pixmap != pixmapsEnd; ++pixmap) {
        for (auto size = pixmap->sizes.begin(), sizesEnd = pixmap->sizes.end(); size != sizesEnd;
             ++size) {
            if (size->loadState == Loading) {
                insertEnd(size->started,
                          modelManager()->traceTime()->endTime() - startTime(size->started));
                size->loadState = Error;
            }
        }
    }
}
Exemplo n.º 10
0
void QmlProfilerRangeModel::loadEvent(const QmlEvent &event, const QmlEventType &type)
{
    Q_UNUSED(type);
    // store starttime-based instance
    if (event.rangeStage() == RangeStart) {
        int index = insertStart(event.timestamp(), event.typeIndex());
        m_stack.append(index);
        m_data.insert(index, QmlRangeEventStartInstance());
    } else if (event.rangeStage() == RangeEnd) {
        if (!m_stack.isEmpty()) {
            int index = m_stack.pop();
            insertEnd(index, event.timestamp() - startTime(index));
        } else {
            qWarning() << "Received inconsistent trace data from application.";
        }
    }
}
Exemplo n.º 11
0
int main(void)
{

    // input data
    char input_data[] = {'f', 'o', 'o', 'b', 'a', 'r'};
    
    // init
    LinkedList *mylist = newCharList();

    // some input
    int i;
    for (i = 0; i < (int)(sizeof(input_data)/sizeof(input_data[0])); i++)
    {
        printf("insertEnd: %c\n", input_data[i]);
        insertEnd(mylist, newCharNode(input_data[i]));
    }

    // output
    printf("printList: \n");
    printList(mylist);

    // remove some
    printf("remove last node\n");
    removeNode(mylist, getLastNode(mylist));
    printf("remove last node\n");
    removeNode(mylist, getLastNode(mylist));

    // output
    printf("printList: \n");
    printList(mylist);

    // remove list
    printf("remove whole list\n");
    removeList(&mylist);

    // output (error operation)
    printf("try to print an empty list\n");
    printList(mylist);

    return 0;
}
 ListNode* oddEvenList(ListNode* head) {
     if(!head || !head->next)
         return head;
     ListNode* odd = head;
     ListNode* even = NULL;
     ListNode* end = NULL, *temp = odd,*prev = NULL,*del = NULL;
     while(temp && temp->next) {
         insertEnd(&even,&end,temp->next->val);
         del = temp->next;
         prev = temp;
         temp->next = temp->next->next;
         free(del);
         temp = temp->next;
     }
     if(temp == NULL) {
         prev->next = even;
     }
     else {
         temp->next = even;
     }
     return odd;
 }
Exemplo n.º 13
0
/* Ultimately there is no way to know which cache entry a given event refers to as long as we only
 * receive the pixmap URL from the application. Multiple copies of different sizes may be cached
 * for each URL. However, we can apply some heuristics to make the result somewhat plausible by
 * using the following assumptions:
 *
 * - PixmapSizeKnown will happen at most once for every cache entry.
 * - PixmapSizeKnown cannot happen for entries with PixmapLoadingError and vice versa.
 * - PixmapCacheCountChanged can happen for entries with PixmapLoadingError but doesn't have to.
 * - Decreasing PixmapCacheCountChanged events can only happen for entries that have seen an
 *   increasing PixmapCacheCountChanged (but that may have happened before the trace).
 * - PixmapCacheCountChanged can happen before or after PixmapSizeKnown.
 * - For every PixmapLoadingFinished or PixmapLoadingError there is exactly one
 *   PixmapLoadingStarted event, but it may be before the trace.
 * - For every PixmapLoadingStarted there is exactly one PixmapLoadingFinished or
 *   PixmapLoadingError, but it may be after the trace.
 * - Decreasing PixmapCacheCountChanged events in the presence of corrupt cache entries are more
 *   likely to clear those entries than other, correctly loaded ones.
 * - Increasing PixmapCacheCountChanged events are more likely to refer to correctly loaded entries
 *   than to ones with PixmapLoadingError.
 * - PixmapLoadingFinished and PixmapLoadingError are more likely to refer to cache entries that
 *   have seen a PixmapLoadingStarted than to ones that haven't.
 *
 * For each URL we keep an ordered list of pixmaps possibly being loaded and assign new events to
 * the first entry that "fits". If multiple sizes of the same pixmap are being loaded concurrently
 * we generally assume that the PixmapLoadingFinished and PixmapLoadingError events occur in the
 * order we learn about the existence of these sizes, subject to the above constraints. This is not
 * necessarily the order the pixmaps are really loaded but it's the best we can do with the given
 * information. If they're loaded sequentially the representation is correct.
 */
void PixmapCacheModel::loadEvent(const QmlEvent &event, const QmlEventType &type)
{
    PixmapCacheItem newEvent;
    const PixmapEventType pixmapType = static_cast<PixmapEventType>(type.detailType());
    newEvent.pixmapEventType = pixmapType;
    qint64 pixmapStartTime = event.timestamp();

    newEvent.urlIndex = -1;
    for (auto i = m_pixmaps.cend(), begin = m_pixmaps.cbegin(); i != begin;) {
        if ((--i)->url == type.location().filename()) {
            newEvent.urlIndex = i - m_pixmaps.cbegin();
            break;
        }
    }

    newEvent.sizeIndex = -1;
    if (newEvent.urlIndex == -1) {
        newEvent.urlIndex = m_pixmaps.count();
        m_pixmaps << Pixmap(type.location().filename());
    }

    Pixmap &pixmap = m_pixmaps[newEvent.urlIndex];
    switch (pixmapType) {
    case PixmapSizeKnown: {// pixmap size
        // Look for pixmaps for which we don't know the size, yet and which have actually been
        // loaded.
        for (auto i = pixmap.sizes.begin(), end = pixmap.sizes.end(); i != end; ++i) {
            if (i->size.isValid() || i->cacheState == Uncacheable || i->cacheState == Corrupt)
                continue;

            // We can't have cached it before we knew the size
            Q_ASSERT(i->cacheState != Cached);

            i->size.setWidth(event.number<qint32>(0));
            i->size.setHeight(event.number<qint32>(1));
            newEvent.sizeIndex = i - pixmap.sizes.begin();
            break;
        }

        if (newEvent.sizeIndex == -1) {
            newEvent.sizeIndex = pixmap.sizes.length();
            pixmap.sizes << PixmapState(event.number<qint32>(0), event.number<qint32>(1));
        }

        PixmapState &state = pixmap.sizes[newEvent.sizeIndex];
        if (state.cacheState == ToBeCached) {
            m_lastCacheSizeEvent = updateCacheCount(m_lastCacheSizeEvent, pixmapStartTime,
                                          state.size.width() * state.size.height(), newEvent,
                                          event.typeIndex());
            state.cacheState = Cached;
        }
        break;
    }
    case PixmapCacheCountChanged: {// Cache Size Changed Event
        bool uncache = m_cumulatedCount > event.number<qint32>(2);
        m_cumulatedCount = event.number<qint32>(2);
        qint64 pixSize = 0;

        // First try to find a preferred pixmap, which either is Corrupt and will be uncached
        // or is uncached and will be cached.
        for (auto i = pixmap.sizes.begin(), end = pixmap.sizes.end(); i != end; ++i) {
            if (uncache && i->cacheState == Corrupt) {
                newEvent.sizeIndex = i - pixmap.sizes.begin();
                i->cacheState = Uncacheable;
                break;
            } else if (!uncache && i->cacheState == Uncached) {
                newEvent.sizeIndex = i - pixmap.sizes.begin();
                if (i->size.isValid()) {
                    pixSize = i->size.width() * i->size.height();
                    i->cacheState = Cached;
                } else {
                    i->cacheState = ToBeCached;
                }
                break;
            }
        }

        // If none found, check for cached or ToBeCached pixmaps that shall be uncached or
        // Error pixmaps that become corrupt cache entries. We also accept Initial to be
        // uncached as we may have missed the matching PixmapCacheCountChanged that cached it.
        if (newEvent.sizeIndex == -1) {
            for (auto i = pixmap.sizes.begin(), end = pixmap.sizes.end(); i != end; ++i) {
                if (uncache && (i->cacheState == Cached || i->cacheState == ToBeCached)) {
                    newEvent.sizeIndex = i - pixmap.sizes.begin();
                    if (i->size.isValid())
                        pixSize = -i->size.width() * i->size.height();
                    i->cacheState = Uncached;
                    break;
                } else if (!uncache && i->cacheState == Uncacheable) {
                    // A pixmap can repeatedly be cached, become corrupt, and the be uncached again.
                    newEvent.sizeIndex = i - pixmap.sizes.begin();
                    i->cacheState = Corrupt;
                    break;
                }
            }
        }

        // If that does't work, create a new entry.
        if (newEvent.sizeIndex == -1) {
            newEvent.sizeIndex = pixmap.sizes.length();
            pixmap.sizes << PixmapState(uncache ? Uncached : ToBeCached);
            // now the size is 0. Thus, there is no point in updating the size row.
        } else if (pixSize != 0) {
            m_lastCacheSizeEvent = updateCacheCount(m_lastCacheSizeEvent, pixmapStartTime, pixSize,
                                                    newEvent, event.typeIndex());
        }
        break;
    }
    case PixmapLoadingStarted: { // Load
        // Look for a pixmap that hasn't been started, yet. There may have been a refcount
        // event, which we ignore.
        for (auto i = pixmap.sizes.cbegin(), end = pixmap.sizes.cend(); i != end; ++i) {
            if (i->loadState == Initial) {
                newEvent.sizeIndex = i - pixmap.sizes.cbegin();
                break;
            }
        }
        if (newEvent.sizeIndex == -1) {
            newEvent.sizeIndex = pixmap.sizes.length();
            pixmap.sizes << PixmapState();
        }

        PixmapState &state = pixmap.sizes[newEvent.sizeIndex];
        state.loadState = Loading;
        newEvent.typeId = event.typeIndex();
        state.started = insertStart(pixmapStartTime, newEvent.urlIndex + 1);
        m_data.insert(state.started, newEvent);
        break;
    }
    case PixmapLoadingFinished:
    case PixmapLoadingError: {
        // First try to find one that has already started
        for (auto i = pixmap.sizes.cbegin(), end = pixmap.sizes.cend(); i != end; ++i) {
            if (i->loadState != Loading)
                continue;
            // Pixmaps with known size cannot be errors and vice versa
            if (pixmapType == PixmapLoadingError && i->size.isValid())
                continue;

            newEvent.sizeIndex = i - pixmap.sizes.cbegin();
            break;
        }

        // If none was found use any other compatible one
        if (newEvent.sizeIndex == -1) {
            for (auto i = pixmap.sizes.cbegin(), end = pixmap.sizes.cend(); i != end; ++i) {
                if (i->loadState != Initial)
                    continue;
                // Pixmaps with known size cannot be errors and vice versa
                if (pixmapType == PixmapLoadingError && i->size.isValid())
                    continue;

                newEvent.sizeIndex = i - pixmap.sizes.cbegin();
                break;
            }
        }

        // If again none was found, create one.
        if (newEvent.sizeIndex == -1) {
            newEvent.sizeIndex = pixmap.sizes.length();
            pixmap.sizes << PixmapState();
        }

        PixmapState &state = pixmap.sizes[newEvent.sizeIndex];
        // If the pixmap loading wasn't started, start it at traceStartTime()
        if (state.loadState == Initial) {
            newEvent.pixmapEventType = PixmapLoadingStarted;
            newEvent.typeId = event.typeIndex();
            qint64 traceStart = modelManager()->traceTime()->startTime();
            state.started = insert(traceStart, pixmapStartTime - traceStart,
                                   newEvent.urlIndex + 1);
            m_data.insert(state.started, newEvent);

            // All other indices are wrong now as we've prepended. Fix them ...
            if (m_lastCacheSizeEvent >= state.started)
                ++m_lastCacheSizeEvent;

            for (int pixmapIndex = 0; pixmapIndex < m_pixmaps.count(); ++pixmapIndex) {
                Pixmap &brokenPixmap = m_pixmaps[pixmapIndex];
                for (int sizeIndex = 0; sizeIndex < brokenPixmap.sizes.count(); ++sizeIndex) {
                    PixmapState &brokenSize = brokenPixmap.sizes[sizeIndex];
                    if ((pixmapIndex != newEvent.urlIndex || sizeIndex != newEvent.sizeIndex) &&
                            brokenSize.started >= state.started) {
                        ++brokenSize.started;
                    }
                }
            }
        } else {
            insertEnd(state.started, pixmapStartTime - startTime(state.started));
        }

        if (pixmapType == PixmapLoadingError) {
            state.loadState = Error;
            switch (state.cacheState) {
            case Uncached:
                state.cacheState = Uncacheable;
                break;
            case ToBeCached:
                state.cacheState = Corrupt;
                break;
            default:
                // Cached cannot happen as size would have to be known and Corrupt or
                // Uncacheable cannot happen as we only accept one finish or error event per
                // pixmap.
                Q_UNREACHABLE();
            }
        } else {
            state.loadState = Finished;
        }
        break;
    }
    default:
        break;
    }
}
Exemplo n.º 14
0
int main(int argc, char ** argv)
{
	struct rec * head = NULL;
	int recNum, i, input;
	int menu = 0;
	char name[100];
	char usrOption = 'y';
	double wNum, hNum, bmi;

	printf("How many records would you like to create?\n");
    scanf("%d",&recNum);

    for(i = 0; i < recNum; i++){
    	printf("Name: - ");
    	scanf("%s", name);
    	printf("Weight (kg): - ");
    	scanf("%lf", &wNum);
    	printf("Height (cm): - ");
    	scanf("%lf", &hNum);
    	bmi = calcBmi(wNum, hNum);
    	insertEnd(&head, wNum, hNum, bmi, name, recNum);
    }

    while(menu == 0){
	    printf("\n1. Print Records\n2. Add a record\n3. Send to file\n4. Sort List\n5. Delete a Record\n6. Quit\n");
	    scanf("%d", &input);
	    //If user would like to print the patient records
	    if(input == 1){
	    	printRecs(head);
	    }
	    //Add a new patient record
	    else if(input == 2){
	    	printf("Name: - ");
    		scanf("%s", name);
    		printf("Weight (kg): - ");
	    	scanf("%lf", &wNum);
	    	printf("Height (cm): - ");
	    	scanf("%lf", &hNum);
	    	bmi = calcBmi(wNum, hNum);
	    	recNum++;
	    	addRecord(&head, wNum, hNum, bmi, name, recNum);
	    }
		//Send records to a file
	    else if(input == 3){
			toFile(head);
	    }
	
		//Sorts the list alphabetically
		else if(input == 4){
			printf("This feature is currently in development.\n");
			sortList(&head);
		}

		//If user would like to delete records
		else if(input == 5){
			if(head->next != NULL){
				printf("Which record would you like to delete?\n");
				scanf("%s", name);
			   	removeRecord(&head, name);
			}
			else{
				printf("Sorry! There was a problem with deleting the record!\n");
			}
		}

		//User wishes to quit program
		else if(input == 6){
			printf("Closing Records.\n");
			menu = 1;
		}
		else{
			printf("Sorry! Please enter a valid input.\n");
		}
	}

    destroy(&head);

    return(0);
}
Exemplo n.º 15
0
int main(int argc, char **argv) {
	dlist *list;
	dlist *list2;
	dlist *list3;
	dlist *list4;
	int choice;
	int i = 0;
	int numData;
	Node *p;
	FILE *fin, *fout;
	int select = 0;
	int startFrom, numSplit; // where to split and the length of splitting list
	char fileName[15]; //file name for output data
	char textName1[20], textName2[20]; // file name for split lists

	char sections [MAX][40] = {"Import from phonebook.dat", "Display (traverse)", "Add new contact (insert before/after)",
	                           "Insert a position" , "Delete a position", "Delete current",
	                           "Delete first", "Search and Update", "Divide and Extract",
	                           "Reverse list", "Save to file", "Count max identical phone numbers", "Exit (free)"
	                          };


	do {
		choice = getMenu(sections, MAX);
		switch (choice) {
		case 1:

			// if ((fin = fopen(argv[1], "r")) == NULL)
			// {
			// 	printf("Can't open file %s\n", argv[1]);
			// 	exit(1);
			// }
			// if ((fout = fopen(argv[2], "wb")) == NULL)
			// {
			// 	printf("Can't open file %s\n", argv[2]);
			// 	exit(1);
			// }

			// numData = importDB(fin, fout);

			// fclose(fin);
			// fclose(fout);

			list = iniList(list);
			list2 = iniList(list2);
			list3 = iniList(list3);
			list4 = iniList(list4);
			if ((fin = fopen(argv[1], "rb")) == NULL)
			{
				printf("Can't open file %s\n", argv[1]);
				exit(1);
			}
			fseek(fin, 0, SEEK_END);
			numData = ftell(fin) / sizeof(element_type);
			rewind(fin);
			result = import(fin, numData);
			for (i = 0; i < result; ++i)
				insertEnd(contact[i], list);
			// printData();
			fclose(fin);
			break;
		case 2:
			traverse(list);
			break;
		case 3:
			printf("Enter 0 to insert before, 1 to insert after: ");
			scanf("%d", &select);
			while (getchar() != '\n');
			if (select == 0)
				insertBefore(list->root, typeHand(), list);
			else
				insertEnd(typeHand(), list);
			break;
		case 4: printf("Position to insert after (1 means root element): ");
			scanf("%d", &select);
			printf("Type in the data to insert\n");
			while (getchar() != '\n');
			if (select < numData)
				insertAfter(locateNode(select, list), typeHand(), list);
			else
				insertEnd(typeHand(), list);
			break;
		case 5: printf("Position to delete: (1 means root element)");
			scanf("%d", &select);
			delNode(locateNode(select, list), list);
			break;
		case 6: delNode(list->cur, list);
			break;
		case 7: delNode(list->root, list);
			break;
		case 8: searchName();
			while (1) {

				printf("Update for position number (type -1 to stop updating): ");
				scanf("%d", &select);
				while (getchar() != '\n');
				if (select == -1)
					break;

				insertAfter(locateNode(select, list), typeHand(), list);
				delNode(locateNode(select, list), list);
				printf("Update success\n");
			}
			break;
		case 9:
			printf("The length of the list is %d\n", listLength(list));
			printf("Type in where to start (range from 1 to end of the list): ");
			scanf("%d", &startFrom);
			printf("Length of spliting: ");
			scanf("%d", &numSplit);
			if (listLength(list) > startFrom + numSplit)
				splitList(startFrom, numSplit, list, list2, list3);
			else
				splitList(startFrom, listLength(list) - startFrom, list, list2, list3);
			while (getchar() != '\n');
			printf("Now type in 2 file name to save the new lists\n");
			printf("File 1: ");
			scanf("%s", textName1);
			printf("File 2: ");
			scanf("%s", textName2);
			checkList(list2, textName1); //result of splitList
			checkList(list3, textName2);
			break;
		case 10:
			reverseList(list);
			break;
		case 11:
			printf("Type in the file name\n");
			scanf("%s", fileName);
			if ((fout = fopen(fileName, "w + t")) == NULL)
			{
				printf("Can't open file %s\n", fileName);
				exit(1);
			}
			savetoFile(fout, list);
			break;
		case 12:
			list4 = countsameNum(list, list4);
			printf("After spliting, the new list with identical numbers: \n");
			p = list4->root;
			while ( p != NULL ) {
				printf("Node with phone number: %s, address %p\n", p->element.tel, p);
				p = p->next;
			}
			break;
		case MAX:
			freeList(list);
			freeList(list2);
			freeList(list3);
			freeList(list4);
			exit(1);
			break;
		default: printf("Invalid choice. It must be from 1 to %d\n", MAX); break;
		}
	} while (choice != MAX);
	return 0;
}
Exemplo n.º 16
0
int main()
{
	List l;

	//createListNoNodes(&l); // working

	Info data1;
	data1.firstName = "felipe";
	data1.lastName = "Cantagalli";
	data1.puid = 27296830;
	data1.age = 22;

	Info data2;
	data2.firstName = "bibi";
	data2.lastName = "letti";
	data2.puid = 12345678;
	data2.age = 20;

	Info data3;
	data3.firstName = "ricardo";
	data3.lastName = "cantagalli";
	data3.puid = 87654321;
	data3.age = 50;

	Info data4;
	data4.firstName = "suzete";
	data4.lastName = "tozato";
	data4.puid = 43256789;
	data4.age = 48;

	createListNode(&l,data1); // working

	printList(&l);

	insertFront(&l, data2); // working
	//insertFront(&l,data3);
	//insertFront(&l,data4);
	printList(&l);
	//insertEnd(&l, data2); //working
	insertEnd(&l,data3);
	insertFront(&l,data4);
	printList(&l);

	//insertMiddle(&l,data4,1); //working

	//deleteFront(&l); // working
	//deleteFront(&l);

	//deleteEnd(&l);
	//deleteEnd(&l);

	deleteMiddle(&l,1); // wroking
	//deleteMiddle(&l,1);

	printList(&l);


	//Node* n = lookUpByIndex(&l,1);
	//printf(" %s\n",n->data.firstName);
	//n = lookUpByIndex(&l,0);
	//printf(" %s\n",n->data.firstName);

	int aux = traverse(&l,27296831);
	//printf("funcionou ?! : %d",aux);

	return 0;
}
Exemplo n.º 17
0
int main()
{
    char ch , a='y';
    int choice, c, token;
    printf("Enter your choice for which deque operation you want to perform operation \n");
     do
     {
          printf("\n1.Input-restricted deque \n");
          printf("2.output-restricted deque \n");
          printf("\nEnter your choice for the operation : ");
          scanf("%d",&c);
          switch(c)
          {
               case 1:
                    printf("\nDo operation in Input-Restricted c deque\n");
                    printf("1.Insert");
                    printf("\n2.Delete from end");
                    printf("\n3.Delete from begning");
                    printf("\n4.show or display");
                    do
                   {
                   printf("\nEnter your choice for the operation in c deque: ");
                   scanf("%d",&choice);
                   switch(choice)
                   {
                       case 1: insertEnd(token);
                       display();
                       break;
                       case 2: token=delEnd();
                       printf("\nThe token deleted is %d",token);
                       display();
                       break;
                       case 3: token=delStart();
                       printf("\nThe token deleted is %d",token);
                       display();
                       break;
                       case 4: display();
                       break;
                       default:printf("Wrong choice");
                       break;
                   }
                   printf("\nDo you want to continue(y/n) to do operation in input-restricted c deque: ");
                   ch=getch();
                   }
                   while(ch=='y'||ch=='Y');
                   getch();
                   break;

               case 2 :
                   printf("\nDo operation in Output-Restricted c deque\n");
                   printf("1.Insert at the End");
                   printf("\n2.Insert at the begning");
                   printf("\n3.Delete the element");
                   printf("\n4.show or display");
                   do
                   {
                   printf("\nEnter your choice for the operation: ");
                   scanf("%d",&choice);
                   switch(choice)
                       {
                       case 1: insertEnd(token);
                       display();
                       break;
                       case 2: insertStart(token);
                       display();
                       break;
                       case 3: token=delStart();
                       printf("\nThe token deleted is %d",token);
                       display();
                       break;
                       case 4: display();
                       break;
                       default:printf("Wrong choice");
                       break;
                       }
                   printf("\nDo you want to continue(y/n):");
                   ch=getch();
                   }
                   while(ch=='y'||ch=='Y');
                   getch();
                   break ;
          }

     printf("\nDo you want to continue(y/n):");
                   ch=getch();
                   }
                   while(ch=='y'||ch=='Y');
                   getch();
}
Exemplo n.º 18
0
void addUser(LinkList L, ClientInf user)
{
    if (!inList(L, user))
        insertEnd(L, user);
}