Exemple #1
0
int main(int argc, char* argv[])
{
	struct clinklist* myLl = createlinklist();
	struct data* myDta=NULL;
	myDta = createData(1.1,2.2);
	addFront(myLl,myDta);
	printList(myLl);
printf("\n");

	myDta = createData(3.3,4.4);
	addFront(myLl,myDta);
	printList(myLl);
printf("\n");

	myDta = createData(5.5,6.6);
	addFront(myLl,myDta);
	printList(myLl);
printf("\n");

	myDta = createData(0.0,0.0);
	addBack(myLl,myDta);
	printList(myLl);
printf("\n");
	

  return 0;
}
Exemple #2
0
int main(){
  auto l = new Chyld::LL<int>();
  l->addFront(3);
  std::cout << l << std::endl;
  l->addFront(5);
  std::cout << l << std::endl;
  return 0;
}
int main()
{
    int ch,data;
    do
    {
        printf("1.Add at rear\n2.Add at front\n3.Remove from rear\n4.remove from front\n5.Display\n0.exit\n");
        scanf("%d",&ch);
        switch(ch)
        {
        case 1:printf("Enter data : ");
                scanf("%d",&data);
                addRear(data);
            break;
        case 2:printf("Enter data : ");
                scanf("%d",&data);
                addFront(data);
            break;
        case 3:removeRear();
            break;
        case 4:removeFront();
            break;
        case 5:display();
            break;
        case 0:printf("\nExitting\n");
            break;
        }
    }while(ch!=0);
    return 0;
}
Exemple #4
0
void parser(char * argv[], Node * head, Hash ** hashTable, int size)
{
	char line[MAXLINELENGTH];
    FILE * infile;
    char * returnValue;
    char * firstName;
    char * lastName;
    Node * tail;
    Node * node;
    char * phoneNumber;
    infile = fopen(argv[1], "r");
    if (infile == NULL)
    {
        printf("error opening file \n");
        exit(0);
    }
    returnValue = fgets(line, MAXLINELENGTH, infile);
    while (returnValue != NULL)
    {
        firstName = strtok(line, ",");
        lastName = strtok(NULL, ",");
        phoneNumber = strtok(NULL, "\n");
        node = addFront(head, phoneNumber, firstName, lastName);
        addToTable(node, hashTable, size);
        returnValue = fgets(line, MAXLINELENGTH, infile);
    }
    tail = getTail(head);
    //quickSort(head -> next, tail);
    fclose(infile);
}
/**
 * Add at position i of the linkList
 * Note: index is not zero-based
 */
void addatPosition(dlinklist *ll,int position,float value)
{
	int length = listSize(ll);
	if(position > length + 1) {
		printf("You entered the position out of the bound!\n");
		return;
	}
	node *temp;
	int i = 1;
	data *newData = createData(value);

	if(position == 1) {
		//insert here - addFront and return;
		addFront(ll,newData);
	} else if(position == length + 1) {
		//insert here - addBack and return;
		addBack(ll,newData);
	}

	node *newNode = createNode(newData);
	for(temp= ll->head; temp != NULL; temp=temp->next) {
		if(i == position) {
			//insert here and return;
			temp->prev->next = newNode;
			newNode->next = temp;
			newNode->prev = temp->prev;
			temp->prev = newNode;
#if DEBUG
			printf(">>==============Node added at position %d with value : %f================<<\n",position,value);
#endif
			return;
		}
		i++;
	}
}
Exemple #6
0
void llist::addbeforeIth(int I, el_t New)
{
          // case(exception)
          // ---------------
          if(I < 1 || I > Count + 1)
            throw OutOfRange();

          // case(I is the front)
          // --------------------
          else if(I == 1)
            addFront(New);

          // case(I is the rear)
          // -------------------
          else if(I == Count + 1)
            addRear(New);

          // case(I will be squished between two nodes)
          // ------------------------------------------
          else
          {
            Node *temp_P = Front;
            Node *temp_N;
            for(int j = 1; j < I - 1; j++)
              temp_P = temp_P->Next;

            temp_N = temp_P->Next;
            temp_P->Next = new Node;
            temp_P = temp_P->Next;
            temp_P->Elem = New;
            temp_P->Next = temp_N;
            Count++;
          }
}
Exemple #7
0
void llist::addRear(el_t New)
{
        // case(first node in the list)
        // ----------------
        // calls addFront to place a node in the list
        // then rear will be pointing to front
        if(isEmpty())
          addFront(New);

        // case(regular case)
        // ------------------
        else
        {
          // rear will point to a newly created Node
          // current rear will move to the new Node
          // strore the number into the node
          // increment count

          Rear->Next = new Node;
          Rear = Rear->Next;
          Rear->Elem = New;
          Rear->Next = NULL;
          Count++;
        }
}
int main()
{
    system("color 0a");
    int ch,data;
    do
    {
        printf("Enter choice : \n1. Add at rear\n2.Add at front\n3.Remove from rear\n4.Remove from Front\n5.Display\n6.search for an item\n0. to exit\n");
        scanf("%d",&ch);
        switch(ch)
        {
        case 1:printf("Enter data :");
            scanf("%d",&data);
            addRear(data);
            break;
        case 2:
            printf("Enter data :");
            scanf("%d",&data);
            addFront(data);
            break;
        case 3:removeRear();
            break;
        case 4:removeFront();
            break;
        case 5:display();
            break;
        case 6:
            printf("Enter data to search :");
            scanf("%d",&data);
            search(data);
            break;

        }
    }while(ch!=0);
    return 0;
}
void StringLinkedList::insert(int index, const std::string& e) {
	if (index < 0 || index > n){
		throw OutOfBoundException("index is out of bounds");
	}
	
	else
{
		StringNode* node = head, *prev = new StringNode;
		StringNode* v = new StringNode;
		v->elem = e;
		int pos = 0;
		while (pos != index  && node-> next != NULL){
			prev = node;
			node = node->next;
			pos++;
		}
		if(index == 0) addFront(e);
		else if(index == n) addBack(e);
		else{
		prev->next = v;
		v->next = node;
		n++;
		}
	}
}
void LightCycle::initBike() {
	addFront();
	addBack();
	addBottomBar();
	addBottomDetails();
	addEngineBlock();
	addInnerCircles();
	addLayeredCircles();
}
Exemple #11
0
void addAfter(struct List *list,
    struct Node *prevNode, struct Node *newNode)
{
    if (prevNode == NULL)
       addFront(list, newNode);

    newNode->next = prevNode->next;
    prevNode->next = newNode;
}
Exemple #12
0
Fichier : ht.c Projet : wfei/hw
//hash_insert
void tableInsert(HT hashTable, ElemType *words, int (*hashFun)(ElemType *word, int size)){
        
    ElemType keyTemp[keySize];
    strcpy(keyTemp, words);

    //re-order the words from dictionary 
    sortWords(keyTemp);

    //calculate hash value
    int hValue = hashFun(keyTemp, hashTable->tableSize);

    /* if (strcmp(words, "ably") == 0 || strcmp(words, "boas") == 0) { */
    /* 	printf("%s %d\n", words, hValue); */
    /* } */

    //add words to bucket
    addFront(hashTable, hValue, words);
    
}// end of tableInsert
void MyInitThreads ()
{
	int i;
	int t;
	int s;

	if (MyInitThreadsCalled) {                /* run only once */
		Printf ("InitThreads: should be called only once\n");
		Exit ();
	}

	for (i = 0; i < MAXTHREADS; i++) {	/* initialize thread table */
		thread[i].valid = 0;
		queue[i].valid = 0;
		queue[i].prev = -1;
		queue[i].next = -1;
	}

	thread[0].valid = 1;			/* initialize thread 0 */

	addFront(0);
	if(debug){
		Printf("Front: %d Back: %d prev: %d next: %d size: %d \n",front,back,queue[0].prev,queue[0].next,queuesize );
	}

	if ((s =setjmp(thread[0].env_clean)) == 0){
		for (i = 1; i <= MAXTHREADS; i ++){
			char s[i*STACKSIZE];
			if (((int) &s[STACKSIZE-1]) - ((int) &s[0]) + 1 != STACKSIZE)  Exit ();
			if ((t = setjmp(thread[i].env_clean)) != 0){
				if(debug) Printf("longjmp %d\n",t);
				(*thread[t-1].func) (thread[t-1].param);
				MyExitThread();
			}
		}
	}
	else{
		(*thread[0].func) (thread[0].param);
		MyExitThread();
	}
	MyInitThreadsCalled = 1;
}
Exemple #14
0
/*PROBABLY or MOST LIKELY DOESN"T WORK!!!!!!!*/
node * addBack (node * head, Sparse * num)
{
  node * newNode = NULL;
  node * back = head;
  
  if(head == NULL)
  {
    newNode = addFront(head, num);
  }
  else
  {
    while(back->next != NULL)
      back = back->next;
    newNode = createNode(num);
    back->next = newNode;
    newNode->next = NULL;
  }
  
  return head;
}
Exemple #15
0
/**
 * \brief    Constructeur de l'éditeur de document
 * \param    d  document ressource
 */
DocumentEditor::DocumentEditor(Document *d, QWidget *parent) :
    NoteEditor(d, parent), resource(d){

    // add or create note
    QPushButton* addBtn = new QPushButton("Ajouter une note existante");
    QObject::connect(addBtn, SIGNAL(clicked()), this, SLOT(addFront()));
    QPushButton* createBtn = new QPushButton("Créer une note");
    QObject::connect(createBtn, SIGNAL(clicked()), this, SLOT(createFront()));
    QHBoxLayout* addLayout = new QHBoxLayout();
    addLayout->addWidget(addBtn);
    addLayout->addWidget(createBtn);

    // scroll area
    QWidget* mainWidget = new QWidget(this);
    QVBoxLayout * vLayout = new QVBoxLayout(mainWidget);
    QScrollArea * scrollArea = new QScrollArea(mainWidget);
    scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
    scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
    scrollArea->setWidgetResizable(false);
    scrollLayout = new QVBoxLayout;
    QWidget* scrollAreaWidgetContents = new QWidget;
    for (Document::iterator it = d->begin(); it != d->end(); ++it){
        DocumentEditorRow* row = new DocumentEditorRow(*it, this);
        rows.push_back(row);
        scrollLayout->addWidget(rows.back());
        QObject::connect(row, SIGNAL(onMoveUp(DocumentEditorRow*)), this, SLOT(moveUp(DocumentEditorRow*)));
        QObject::connect(row, SIGNAL(onMoveDown(DocumentEditorRow*)), this, SLOT(moveDown(DocumentEditorRow*)));
        QObject::connect(row, SIGNAL(onEdit(DocumentEditorRow*)), this, SLOT(edit(DocumentEditorRow*)));
        QObject::connect(row, SIGNAL(onSupress(DocumentEditorRow*)), this, SLOT(supress(DocumentEditorRow*)));
        QObject::connect(row, SIGNAL(onAdd(DocumentEditorRow*)), this, SLOT(add(DocumentEditorRow*)));
        QObject::connect(row, SIGNAL(onCreate(DocumentEditorRow*)), this, SLOT(create(DocumentEditorRow*)));
    }
    scrollAreaWidgetContents->setLayout(scrollLayout);
    scrollLayout->setSizeConstraint(QLayout::SetFixedSize);
    scrollArea->setWidget(scrollAreaWidgetContents);
    vLayout->addWidget(scrollArea);

    // layout
    layout->addLayout(addLayout);
    layout->addWidget(mainWidget);
}
void UINode::addBefore (UINode* reference, UINode* node)
{
	UINodeListIter i = std::find(_nodes.begin(), _nodes.end(), reference);
	if (i == _nodes.end()) {
		add(node);
		return;
	}

	if (i == _nodes.begin()) {
		addFront(node);
		return;
	}

	_nodes.insert(i, node);

	if (_layout)
		_layout->addNode(node);

	node->setParent(this);
	node->onAdd();
}
Exemple #17
0
linkList *readData(char *filename,int addDirection)
{
	FILE* input_file = fopen(filename,"r");
	if(input_file == NULL) {
		printf("Error opening input file %s\n",filename);
		exit(1);
	}
	int i;
	int value = 0.0;
#if DEBUG
	printf(">>==============Creating Linklist=================<<\n");
#endif
	linkList *newlinkList = createlinkList();
	while(fscanf(input_file, "%d", &value) != EOF) {
		addFront(newlinkList,value);
	}
	fclose(input_file);
#if DEBUG
	printf(">>==============Linklist Created=================<<\n\n");
#endif
	return newlinkList;
}
Exemple #18
0
dlinklist *readData(char *filename,int addDirection)
{
	FILE* input_file = fopen(filename,"r");
	if(input_file == NULL) {
		printf("Error opening input file %s\n",filename);
		exit(1);
	}
	float value = 0.0;
#if DEBUG
	printf(">>===============Creating dLinklist=================<<\n");
#endif
	dlinklist *newdlinklist = createlinklist();
	while(fscanf(input_file, "%f", &value) != EOF) {
		data *newData = createData(value);
		addFront(newdlinklist,newData);
	}
	fclose(input_file);
#if DEBUG
	printf(">>==============dLinklist Created=================<<\n\n");
#endif
	return newdlinklist;
}
Exemple #19
0
struct Node *addAfter(struct List *list, 
	struct Node *prevNode, void *data){
 
     if (prevNode == NULL) {
      return addFront(list, data); 
    }
    //printf("%.1f", *(double *)data);
    
    struct Node *mynode = (struct Node*) malloc (sizeof (struct Node));
    //node = addAfter(&list, node, a+i);
    if (mynode == NULL){
       return NULL;
    }

    mynode->data = data; // assign the data to the new node

    struct Node *prevNodeNext = prevNode->next; //a node to hold the prevNodeNext 
    prevNode->next = mynode; // now the next of the prevNode is the new node
    mynode->next = prevNodeNext; // in the test is always null
    
    return mynode;  
    
}
Exemple #20
0
void push(Stack * stack, Element * element){
    
    addFront(stack->top, element);
}
Exemple #21
0
void getPointsFromFileSquare
(
	FILE *  filePtr,
	Node ** head,
	double  centroidEasting,
	double  centroidNorthing,
	int     sideLength,
	float   zThreshold,
	int *   numZ,
	int *   numAll
)
{
	puts("extractPointsFromFile");
	
	float s2 = sideLength / 2.0;
	
	double xmin, ymin, xmax, ymax;
	
	xmin = centroidEasting - s2;
	ymin = centroidNorthing - s2;
	xmax = centroidEasting + s2; 
	ymax = centroidNorthing + s2;
	
	ScanHdr * shdr = readTerraScanHdr(filePtr);
	int pnt;
	for(pnt = 0; pnt < shdr->PntCnt; pnt++){
		ScanPnt * spnt = getNextPnt(filePtr);
		double x = (double)((spnt->Pnt.x - shdr->OrgX) / (double)shdr->Units);
		double y = (double)((spnt->Pnt.y - shdr->OrgY) / (double)shdr->Units);
		double z = (double)((spnt->Pnt.z - shdr->OrgZ) / (double)shdr->Units);
		
		if(x > xmin && x < xmax && y > ymin && y < ymax)
		{
			(*numAll)++;
			if(z > zThreshold){
				addFront(head, (float)z);
				(*numZ)++;
			}
		}
		
		if(shdr->Time)fseek(filePtr, 4, SEEK_CUR);
		if(shdr->Color)fseek(filePtr, 4, SEEK_CUR);
		free(spnt);
	}
	free(shdr);
	
	/*
	while(fscanf(filePtr, "%lf %lf %lf", &x, &y, &z) == 3)
	{
		if(x > xmin && x < xmax && y > ymin && y < ymax)
		{
			(*numAll)++;
			if(z > zThreshold)
			{
				addFront( head, (float) z );
				(*numZ)++;
			}
		}
	}
	*/
	printf("\t%d %d \n", *numZ, *numAll);
}
Exemple #22
0
 void push(std::string const& searchDir) {
   addFront(*pDirs, searchDir);  // TODO: deque?
 }
Exemple #23
0
int main () {
    
    int menu = 0;
    int input = 0;
    node * list; 
    char c;
    
    list = createList(); 
    
    while (menu != 6) {
    
        printf("\nWhat would you like to test?\n");
        printf("\n[1] Add Front\n");
        printf("[2] Get Front\n");
        printf("[3] Remove Front\n");
        printf("[4] My Tests\n");
        printf("[5] Destroy List\n");
        printf("[6] Exit\n");
        scanf("%d", &menu);

        if (menu > 6 || menu < 1)
            while((c = getchar()) != '\n' && c != EOF); /*cleans input buffer, incase characters are input*/
            
        if (menu == 1) {
            
            printf("\nPlease Enter an Integer:");
            scanf("%d", &input);
            
            addFront(list, input);  /*returns users input to function to add to the list*/
            
            printf("Current List:");
            printList(list);        /*List printed everytime inorder for user to keep track*/
        
        }
        
        if (menu == 2) {
            
            printf("Front Value: %d", getFront(list));  /*gets value from function and prints it to screen*/
            
            printf("\nCurrent List:");
            printList(list);  
        
        }
        
        if (menu == 3) {
        
            removeFront(list);  /*calls function and sends list to remove first*/
            
            printf("Current List:");
            printList(list);
        
        }
        
        if (menu == 4) {
            
            /*my tests, I have tested very large and very small numbers in this array*/
            int testData[8] = {-456789123, 2, 0, 4, 1, 9, 9, 2096335345}; /*Given Data*/
            int arrayLength;
            int i;
            int testAddFront;
    
            arrayLength = sizeof(testData) / sizeof(int); /*Determines arraylength*/
        
            for (i=0; i<arrayLength; i++) {
                addFront(list, testData[i]);    /*Sends data to the addFront function*/ 
            }
            
            printf("\nAfter sending testData:\n");
            printList(list);
            
            getFront(list);
            printf("\n\nAfter getFront:\n");
            printf("%d", getFront(list));
            
            removeFront(list);
            printf("\n\nAfter removeFront:\n");
            printList(list);
            
            testAddFront = 999999;
            addFront(list, testAddFront);
            printf("\n\nAfter addFront:\n");
            printList(list);
        }
        
        if (menu == 5) {
        
            destroy(list); /*destroys list and frees memory*/
        
        }
        
        if (menu == 6) {
        
            break;  /*breaks out and ends program*/
            
        }
    }
    
    return 0;
}
Exemple #24
0
//push item onto the stack
void pushStack(struct stack *s,struct leaf *dta)
{
  addFront(s->stk,dta);
}
Exemple #25
0
void push(Stack * stack, int value)
{
    addFront(stack -> top, value);
}
Exemple #26
0
void AssemFunc::finalise() {
	// Add the necessary commands to the top and bottom of the function, 
	// depending on if the function is the main entry point, and whether the
	// local stack pointer needs to be moved or not

	// NB: Front intrsuctions are done in reverse

	if (_name == "main") {
		vector<string> args;
		args.push_back("r0");
		args.push_back("#0");
		addBack("mov", args);
	}

	if (_stackPointer > 0) {
		// Only do this if we actually need to move the pointer, avoid 
		// sub sp sp #0 and the like.
		vector<string> spArgs(2, "sp");
		spArgs.push_back("#" + boost::lexical_cast<string>(_stackPointer));
		addFront("sub", spArgs);

		vector<string> fpArgs;
		fpArgs.push_back("fp");
		fpArgs.push_back("sp");
		fpArgs.push_back("#4");
		addFront("add", fpArgs);

		fpArgs.clear();
		fpArgs.push_back("sp");
		fpArgs.push_back("fp");
		fpArgs.push_back("#4");
		addBack("sub", fpArgs);
	} else if (_pointerByReg != "") {

		if (_pointerByReg[0] == '.') {
			// size is in a label
			string tempReg = _freeRegs.front();

			vector<string> spArgs(2, "sp");
			spArgs.push_back(tempReg);
			addFront("sub", spArgs);

			spArgs.clear();
			spArgs.push_back(tempReg);
			spArgs.push_back(_pointerByReg);
			addFront("ldr", spArgs);
		} else {
			vector<string> spArgs(2, "sp");
			spArgs.push_back(_pointerByReg);
			addFront("sub", spArgs);
		}

		vector<string> fpArgs;
		fpArgs.push_back("fp");
		fpArgs.push_back("sp");
		fpArgs.push_back("#4");
		addFront("add", fpArgs);

		fpArgs.clear();
		fpArgs.push_back("sp");
		fpArgs.push_back("fp");
		fpArgs.push_back("#4");
		addBack("sub", fpArgs);
	}

	if (_name == "main") {
		vector<string> args;
		args.push_back("sp!");
		args.push_back("{fp, lr}");
		addFront("stmfd", args);

		args.clear();
		args.push_back("sp!");
		args.push_back("{fp, pc}");
		addBack("ldmfd", args);

		addFront("main:", vector<string>());

		vector<string> globArgs(1, _name);
		addFront(".global", globArgs);
	} else {
		vector<string> args;
		args.push_back("sp!");
		args.push_back("{r4-r10, fp, lr}");
		addFront("stmfd", args);

		args.clear();
		args.push_back("sp!");
		args.push_back("{r4-r10, fp, pc}");
		addBack("ldmfd", args);

		addFront(_name + ":", vector<string>());
	}

	vector<string> alignArgs(1, "2");
	addFront(".align", alignArgs);

}