Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <sys/types.h>
- #include <dirent.h>
- #include <fcntl.h>
- #include <string.h>
- #include <pthread.h>
- pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
- struct Node {
- char *value;
- Node *next;
- };
- struct Queue {
- Node *firstNode;
- Node *lastNode;
- };
- Queue *newQueue() {
- Queue *q = (Queue *)malloc(sizeof(struct Queue));
- q->firstNode = q->lastNode = NULL;
- return q;
- }
- Queue *q = newQueue();
- Node *newNode(char *valueToInsert) {
- Node *nodeToInsert = (Node *)malloc(sizeof(struct Node));
- nodeToInsert->value = (char *)malloc(strlen(valueToInsert));
- strcpy(nodeToInsert->value, valueToInsert);
- nodeToInsert->next = NULL;
- return nodeToInsert;
- }
- void push(Queue *q, char *valueToInsert) {
- Node *nodeToInsert = newNode(valueToInsert);
- if (q->lastNode == NULL) {
- q->firstNode = q->lastNode = nodeToInsert;
- return;
- }
- q->lastNode->next = nodeToInsert;
- q->lastNode = nodeToInsert;
- }
- Node *pop(Queue *q) {
- if (q->firstNode == NULL) {
- return NULL;
- }
- Node *temporaryNode;
- temporaryNode = q->firstNode;
- q->firstNode = q->firstNode->next;
- if (q->firstNode == NULL) {
- q->lastNode = NULL;
- }
- return temporaryNode;
- }
- void printQueue(Queue *q) {
- if (q->lastNode == NULL) {
- printf("%s\n", "Empty queue!");
- return;
- }
- printf("%s", "QUEUE: ");
- Node *temporaryNode = q->firstNode;
- do {
- printf("%s ", temporaryNode->value);
- temporaryNode = temporaryNode->next;
- } while (temporaryNode != NULL);
- printf("\n");
- }
- void recShow(char* dirName) {
- DIR* fileDescriptor;
- struct dirent *d;
- fileDescriptor = opendir(dirName);
- if (fileDescriptor == NULL) {
- printf("%s\n", "Problem with directory opening...");
- return;
- }
- while ((d = readdir(fileDescriptor)) != NULL) {
- printf("%s/%s\n", dirName, d->d_name);
- if (d->d_type == DT_DIR && strcmp(".", d->d_name) != 0 && strcmp("..", d->d_name) != 0) {
- char *newPath = (char*)malloc(strlen(dirName)+strlen(d->d_name)+1);
- strcpy(newPath, dirName);
- strcat(newPath, "/");
- strcat(newPath, d->d_name);
- recShow(newPath);
- }
- }
- closedir(fileDescriptor);
- }
- int main(int argc, char *argv[]) {
- if (argc < 2) {
- printf("%s\n", "Please provide a directory...");
- return 1;
- }
- //recShow(argv[1]);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement