main()
      {
      int n;
      printf("Enter from the following option\n");
      while(1)
              {
              printf("1.Add Elements \n");
              printf("2.Insert At Begining\n");
              printf("3.Insert At end\n");
              printf("4.Insert At Position\n");
              printf("5.Display Element \n");   
              printf("6.Display Reverse\n");
              printf("7.Exit\n");   
              scanf("%d",&n);
              switch(n)
                  {
                  case 1:{
                          insertNodes(count()+1,getValue());//Add elements
                          break;
                          }
                  case 2:{
                          insertNodes(1,getValue());//1 is to signify 1st position 
                          break;
                          }        
                  case 3:{
                          
                         insertNodes(count()+1,getValue());//count returns the number of node
                                                    //count()+1 will add in the last position 
                          break;
                          }        
                  case 4: {
                          int pos;
                          printf("Enter the Position\n");
                          scanf("%d",&pos);
                          if(pos<=count()+1)
                              insertNodes(pos,getValue());
                          else
                              printf("Wrong Position\n");    
                          break;
                          }         
                  case 5:{
                         display();
                         break; 
                          }  
                  case 6:{
                         displayReverse();
                         break; 
                          }          
                  case 7:
                         exit(1);         
                  default:
                          printf("Wrong Input\n");            
                            
                  }
              printf("\n\n");    
              }                    
      }        
示例#2
0
文件: main.c 项目: ikaikastine/OSU
int main() {
    struct node *head;
    struct node *tail;
    
    //Test cases for different values
    insertNodes(&head, 1);
    insertNodes(&head, 2);
    insertNodes(&head, 3);
    insertNodes(&head, 4);
    insertNodes(&head, 5);
    insertNodes(&head, 6);

    //Prints the elements of the linked list before sorting
    printf("%sList before sorting:%s\n", RED, CLEAR);
    printList(head, lengthList(head));
    printf("\n");

    //Calls the sort function
    mergeSort(&head, &tail);

    //Prints the elements of the linked list after sorting
    printf("\n%sList after sorting:%s\n", GREEN, CLEAR);
    printList(head, lengthList(head));
    printf("\n");
    
    return 0;
}
示例#3
0
void odkFormReader::createItemsTree()
{
    treeItems.clear();

    int tblindex;
    int parentindex;

    qSort(tables.begin(),tables.end(),tblComp);

    for (int pos = 0; pos <= tables.count()-1;pos++)
    {
        if (tables[pos].islookup == false)
        {
            if (tables[pos].xmlCode != "NONE")
            {
                //qDebug() << "Table:" + tables[pos].name;
                if (tables[pos].parentTable == "NULL")
                {
                    tblindex = insertNodes(-1,tables[pos].name,tables[pos].name,tables[pos].xmlCode);
                    //qDebug() << tables[pos].xmlCode;
                    tables[pos].parentIndex = tblindex;
                }
                else
                {
                    //qDebug() << "Parent:" + tables[pos].parentTable;
                    parentindex = getTableIndex(tables[pos].parentTable);
                    //qDebug() << "Parent index:" + QString::number(parentindex);

                    tblindex = insertNodes(parentindex,tables[pos].name,tables[pos].name,tables[pos].xmlCode);
                    tables[pos].parentIndex = tblindex;
                }
            }
        }
    }

}
示例#4
0
文件: load.cpp 项目: renqHIT/Tale
void LoadGraph::load(bool forsaga, bool fortale)
{
	//basic indices
	//insert into Graph, Vertex and Edge tables (files on disk)
	insertGraph();
	debug(33, "insert into graph succeeds\n");
	insertNodes();
	debug(33, "insert into node succeeds\n");
	insertEdges();
	debug(33, "insert into edge succeeds\n");
//	insertOrthologs();

	if(forsaga && G->e()>0)
	{
		D=new int* [G->n()];
		for(int i=0; i<G->n(); i++)
		{
			D[i]=new int[G->n()];
		}
		//get distance matrix
		floyd_Min_Dist(G, D);
		debug(33, "got distance matrix!\n");
		
		insertDistances();
		debug(33, "insert into distance succeeds\n");
		//enumerate vertex subset and insert into fragment Table
		insertFragments();
		//deallocate 
		for(int i=0; i<G->n(); i++)
		{
			delete [] D[i];
		}
		delete [] D;
		//debug(33, "insert into fragments succeeds\n");
	}
	
	if(fortale)
	{
		//enumerate neighborhoods and insert into the Neighborhood table (file on disk)
		insertNeighborhoods();
		debug(33, "insert into neighborhoods succeeds\n");
	}
}