int main() { List L = Create(); ElementType e; e = 3; InsertAtHead(e, L); e = 2; InsertAtHead(e, L); e = 1; InsertAtHead(e, L); PrintList(L); L = Reverse(L); PrintList(L); return 0; }
int main() { /*Driver code to test the implementation*/ head = NULL; // empty list. set head as NULL. // Calling an Insert and printing list both in forward as well as reverse direction. InsertAtTail(2); Print(); ReversePrint(); InsertAtTail(4); Print(); ReversePrint(); InsertAtHead(6); Print(); ReversePrint(); InsertAtTail(8); Print(); ReversePrint(); }
DWORD WINAPI mailThread(LPVOID arg) { char buffer[1024]; planet_type *planet = (planet_type*)malloc(sizeof(planet_type)); DWORD bytesRead; static int posY = 0; char mailSlotString[18] = "\\\\.\\mailslot\\", inputString[1024]; HANDLE serverMailslot; /* create a mailslot that clients can use to pass requests through */ /* (the clients use the name below to get contact with the mailslot) */ /* NOTE: The name of a mailslot must start with "\\\\.\\mailslot\\" */ serverMailslot = mailslotCreate("\\\\.\\mailslot\\serverMailslot"); if (serverMailslot == INVALID_HANDLE_VALUE) { MessageBox(0, "Could not create mailslot, exiting.", "Error", 1); Sleep(3000); exit(1); } /* (ordinary file manipulating functions are used to read from mailslots) */ /* in this example the server receives strings from the client side and */ /* displays them in the presentation window */ /* NOTE: binary data can also be sent and received, e.g. planet structures*/ while (1) { bytesRead = mailslotRead(serverMailslot, (void *)planet, sizeof(planet_type)); if (bytesRead != 0) { // If planet name doesnt exist, add it to linked list if (!planetExists(planet)) { EnterCriticalSection(&dbAccess); InsertAtHead(*planet); LeaveCriticalSection(&dbAccess); threadCreate(calculatePosition, &(head->data)); } else { sendErrorToCreator(planet, 2); } } else { /* failed reading from mailslot */ /* (in this example we ignore this, and happily continue...) */ } } free(planet); return 0; }
List Reverse(List L) { Position Left = L->Next; L->Next = NULL; while (Left) { InsertAtHead(Left->Element, L); Left = Left->Next; } return L; }
int valid_operator(char c, char* word, enum command_type *cmd, struct linked_list *cmd_stack, int(*get_next_byte) (void *), void *get_next_byte_argument) { char next; //char *tmp; int retval = 0; if (c == ';') { *cmd = SEQUENCE_COMMAND; retval = 1; } else if (c == '(' || c == ')') { *cmd = SUBSHELL_COMMAND; retval = 1; } else if (c == '|') { next = (char)get_next_byte(get_next_byte_argument); if (next == '|') { *cmd = OR_COMMAND; } else { *cmd = PIPE_COMMAND; char *temp = (char*)malloc(sizeof(char)*(strlen(word) - 1)); } retval = 1; } else if (c == '&') { next = get_next_byte(get_next_byte_argument); if (next == '&') { *cmd = AND_COMMAND; } retval = 1; } if (retval) { //gotta push nontokenized string onto the command stack //FIXME: Need to clean up this nontoken string and check for invalid syntax - as of now newlines and //whitespace are a-ok and we gotta check for that - suggest creating another function struct command simple_cmd; simple_cmd.u.word = (char**)malloc(sizeof(char*)); *(simple_cmd.u.word) = (char*)malloc(sizeof(char)*strlen(word)); **(simple_cmd.u.word) = *word; InsertAtHead(&simple_cmd, cmd_stack); //now clean up the reference variable used in the parser free(word); word = ""; if (*cmd == PIPE_COMMAND) { //tmp = (char *)malloc(sizeof(char) * strlen(&next)) //*tmp = next; strcat(word, &next); } } return retval; }
int main() { List L = Create(); if( L == NULL) { printf("Fatal error: creating list failed!!!\n"); exit(1); } List P = Create(); if( P == NULL) { printf("Fatal error: creating list failed!!!\n"); exit(1); } // Make sure ElementType is int ElementType e; while (scanf("%d", &e) != EOF) { // -1 is the end of L input if (e == -1) break; InsertAtHead(e, L); } while (scanf("%d", &e) != EOF) { InsertAtHead(e, P); } PrintLots(L, P); return 0; }