/* Reads strings from the file into the liked list */
void loadList( CDLL *list, char *infileName)
{
	char *line;
	char ** tokens;
	int tokenCnt=0;
	char * delim = ",";

	FILE* infile = fopen(infileName, "r");
	if(!infile) fatal("Can't open input file");

	while( mygetline( &line, infile ) )
	{
		STUDENT *s = malloc(sizeof(STUDENT));
		if (!s) fatal("malloc( sizeof(STUDENT))  failed in loadList");

		tokens = split( line, &tokenCnt, delim );
		s->andrewID = tokens[0];
		s->name = tokens[1];
		s->yrOfGrad = atoi(tokens[2]);
		s->gpa = atof(tokens[3]);
		s->major = tokens[4];

		insertAtTail( list,  s );

		free(line);
		free(tokens[2]);      /* year */
		free(tokens[3]);      /* major */
		free(tokens);
	}
	fclose(infile);
}
Example #2
0
int main()
{
	LIST *list1, *list2;
	list1=createList(10);
	list2=createList(10);
	int j;
	for(j=0; j<12; j++)
		insertAtHead(list1,j+1);
	printList(list1);

//	for(j=0; j<12; j++)
//		insertAtTail(list2,j+1);
//	printList(list2);

	deleteFromHead(list1);
	deleteFromHead(list1);
	deleteFromHead(list1);
	deleteFromHead(list1);
	printList(list1);
	for(j=0; j<6; j++)
		insertAtTail(list1,99);
	printList(list1);
	printf("\n");
	return 0;
}
Example #3
0
/*	---------------------------------------------------------------------------
	loadList:

	loops from lo value to hi value (from cmd args) appending each int value
	onto the end of the list. DO NOT MALLOC MEMORY FOR THE INT TO BE STORED
	- INSTEAD STORE IT 	*INSIDE* THE DATA POINTER (again..casting!)
*/
void loadList( CDLL *list, int lo, int hi)
{
	int i;
	for(i=lo;i<=hi;i++)
	{
		insertAtTail(list, (void *)i);
	}
}
Example #4
0
/* Reads strings from the file into the liked list */
void loadList( CDLL *list, char *infileName)
{
	FILE* infile = fopen(infileName, "r");
	if(!infile) fatal("Can't open input file");

	char *name;
	while( mygetline( &name, infile ) )
		insertAtTail( list, name );
	fclose(infile);
}
Example #5
0
File: main.c Project: f2008700/BITS
int main()
{
	int i,size=15;
	ElementList E;
	Element e1;
	e1.id=2000;
	e1.regstatus=0;
	for(i=0;i<size;i++)
	{
			E[i].id=i;
			E[i].regstatus=(i%3); //0= Success, 1 = Conflict, 2 = Deny
	}
	// R containing All (size number) registered student records
	ListHead ks, kd, kc;
	ks=createList();
	kd=createList();
	kc=createList();	 				
	for (i = 0; i < size; i++) {
		if  (E[i].regstatus == 0) {
	  		insertAtTail (E[i], ks);
		} else if  (E[i].regstatus == 1) {
			insertAtHead (E[i], kc);
		} else {
			insertInPos (E[i], kd,2);
		}
	}
	insertAfterValue (e1, ks, 12);
	printf("\n\nSUCCESS LIST\n");
	printList(ks);

	printf("\n\nCONFLICT LIST\n");
	printList(kc);

	printf("\n\nDENY LIST\n");
	printList(kd);


	deleteFromHead(ks);
	deleteFromTail(kc);
	deleteValue(kd,8);
	deletePos(ks,0);

	printf("\n\nSUCCESS LIST After Deletion\n");
	printList(ks);

	printf("\n\nCONFLICT LIST After Deletion\n");
	printList(kc);

	printf("\n\nDENY LIST After Deletion\n");
	printList(kd);
	

}
Example #6
0
LinkedList<T>& LinkedList<T>::operator=(const LinkedList<T>& rhs)
{
  if (this==&rhs)
    return *this;
  clear();
  Node<T>* it = rhs.m_head;
  while (it)
  {
    insertAtTail(it->m_data);
    it=it->m_next;
  }
}
Example #7
0
LinkedList<T>& LinkedList<T>:: operator=(const LinkedList<T>& rhs)
{
  if(this == &rhs)
    return *this;
    
  clear();
  Node<T> *temp =  rhs.m_head;
  while(temp != NULL)
  {
    insertAtTail(temp->m_data);
    temp = temp->m_next;
  }  
  
  return *this;
}
Example #8
0
int main()
{
	int userInput;
	struct Node* head;
	struct Node* tail;
	head = NULL;
	tail = NULL;
	
	printWelcomeMsg();
	
	userInput = 0;
	while (userInput != -1) {
		userInput = getSelection("Enter your selection: ");		
		if(userInput == 1) {
			userInput = getSelection("Enter the value to append to head: ");
			insertAtHead(&head, &tail, userInput);
		} else if (userInput == 2) {
			userInput = getSelection("Enter the value to append to tail: ");
			insertAtTail(&tail, &head, userInput);
		} else if (userInput == -1) {
			printExitMessage();
			scanf("%d", &userInput);
			printf("\n");
			if (userInput == 1) {
				printForward(tail);
			} else if (userInput == 2) {
				printReverse(head);
			} else {
				printf("\nExiting without displaying output.");
			}
			return 0;
		}
		else {
			printf("You've made an error. Please try again.\n\n");
		}
	}

	printForward(tail);
	
	return 0;
}
Example #9
0
int main()
{
        struct node *head;
	int data;
	int t;
	int n;
	int i;
    
	/* Enter number of test cases */
	scanf("%d", &t);
	while(t--)
	{
		/* Read number of nodes in the list */
		scanf("%d", &n);
		for(i = 0; i < n; i++)
		{
			scanf("%d", &data);
			insertAtTail(&head, data);
		}
		printll(head);
		printf("\n");
	}
}
Example #10
0
void WhileStmt::copyShare(const WhileStmt& ref,
                          SymbolMap*       mapRef,
                          bool             internal)
{
  SymbolMap  localMap;
  SymbolMap* map       = (mapRef != 0) ? mapRef : &localMap;
  Expr*      condExpr  = ref.condExprGet();

  astloc            = ref.astloc;
  blockTag          = ref.blockTag;

  mBreakLabel       = ref.mBreakLabel;
  mContinueLabel    = ref.mContinueLabel;
  mOrderIndependent = ref.mOrderIndependent;

  if (condExpr != 0)
    mCondExpr = condExpr->copy(map, true);

  for_alist(expr, ref.body)
    insertAtTail(expr->copy(map, true));

  if (internal == false)
    update_symbols(this, map);
}
Example #11
0
IpeSequence::IpeSequence(const std::vector<Expr*>& stmts,
                         BlockTag                  tag) : BlockStmt(NULL, tag)
{
  for (size_t i = 0; i < stmts.size(); i++)
    insertAtTail(stmts[i]);
}
Example #12
0
IpeSequence::IpeSequence(const std::vector<Expr*>& stmts) : BlockStmt(NULL, BLOCK_SCOPELESS)
{
  for (size_t i = 0; i < stmts.size(); i++)
    insertAtTail(stmts[i]);
}
Example #13
0
int main()
{
	LIST *list1;
	list1=createList(10);
	insertAtHead(list1,1);
	insertAtHead(list1,2);
	printList(list1);

	insertAtTail(list1,2);
	insertAtTail(list1,3);
	insertAtTail(list1,4);
	insertAtTail(list1,5);
	insertAtTail(list1,6);
	insertAtTail(list1,7);
	insertAtTail(list1,8);
	insertAtTail(list1,9);
	insertAtTail(list1,10);
	insertAtTail(list1,11);
	printList(list1);

	int res, j;
	for(j=0; j<12; j++)
	{
		res=deleteFromHead(list1);
		if(res>0)
			printf("\nDeleted:\t%d",res);
	}
	printList(list1);

	for(j=0; j<12; j++)
	{
		insertAtHead(list1,j+1);
	}
	printList(list1);

	for(j=0; j<12; j++)
	{
		insertAtTail(list1,j+1);
	}
	printList(list1);

	printf("\nDeleted:\t%d",deleteFromHead(list1));
	printf("\nDeleted:\t%d",deleteFromHead(list1));
	printf("\nDeleted:\t%d",deleteFromHead(list1));
	printList(list1);
	printf("\nDeleted:\t%d",deleteFromTail(list1));
	printf("\nDeleted:\t%d",deleteFromTail(list1));
	printf("\nDeleted:\t%d",deleteFromTail(list1));
	printList(list1);

	for(j=0; j<12; j++)
	{
		res=deleteFromTail(list1);
		if(res>0)
			printf("\nDeleted:\t%d",res);
	}
	printList(list1);

	for(j=0; j<12; j++)
	{
		insertAtTail(list1,j+1);
	}
	printList(list1);

	printf("\n");
	return 0;
}