Section 1 Project Objectives Makes use of Cstring library Re

Section 1: Project Objectives .Makes use of C-string library Read from and write to a text file Design and access structures Array of structures Learn to use pointers to inserting/deleting a node from a LinkedList. Learn to use malloc and-free for dynamic memory allocation. · Learn to use malloc and free for dynamic memory allocation. · Develop test cases to test your program Section 2: Background Introduction Vehicular networking is used to simulate vehicles on the road. In this project, you are required to develop a vehicular networking controller unit which will have high processing capabilities such that each controller can keep track of up to 50 vehicles on the road. Meanwhile each controller will also need to maintain the location of each vehicle and its neighbor-list. Vehicle tracking will occur every N number of seconds. Section 3: Project Description Your project is to write a complete C program which will simulate a network of vehicles. Section 3.1: 1. Create a while loop such that it will keep simulate until terminated by using Ctrl and C (C) command Three functions can be called in this loop: update Location(. when called, this function will update the location (x and y

Solution

SECTION - 1 :-

//Here we are using stack principle to insert and delete element

#include <stdio.h>

#include <stdlib.h>//as we are using malloc() and free()

typedef struct llist

{

   int data;

   struct llist *next;// next is used to denote next element/data in the stack

}stk;

stk *top=NULL;//pointer variable to denote top position of the stack

void push(int ele);//Function to push the element to be inserted into the stack

int pop();//Function to delete the element at the top position following principle LIFO(List In First Out)

void display();//Function to display the stack of elements after respective desired operations

int main()

{

int ch,ele;/*ch variable is used to select the option from switch case(1/2/3/4 options) & ele variable is used to insert the integer element into the stack*/

do/*do while is used as I wanted to display first the intial statements as mentioned below then considering the condition while(1) ...insertion and respective deletion operation takes place*/

{

printf(\"1.INSERTION\ \");

  printf(\"2.DELETION\ \");

  printf(\"3.DISPLAY\ \");

printf(\"4.EXIT\ \");

scanf(\"%d\",&ch);

switch(ch)

{

case 1 : printf(\"Enter Insertion Element\ \");

scanf(\"%d\",&ele);

push(ele);

break;

case 2 : printf(\"Enter Deletion Element\ \");

scanf(\"%d\",&ele);

pop();

break;

case 3 : display();

break;

case 4 : exit(0);

break;

}

}while(1);

}

void push(int ele)

{

stk *node;

node=(stk *)malloc(sizeof (stk));//Dynamic memory allocation using malloc() for node pointer variable

node->data=ele;//data is of integer type and element is placed in first position

node->next=top;//as it follows stack principle next element to be inserted is pointed as first position

top=node;

}

int pop()

{

int ele;

stk *cur;//declared cur pointer variable to place the first element in the stack into this variable

if(top==NULL)

{

printf(\"stk is empty\ \");

return 0;

}

else

{

cur=top;//top positioned data is placed into cur

top=top->next;//pointing the second data in the stack as first position(top)

ele=cur->data;//sending the data in cur (top element) into ele variable

free(cur);//after these operations deallocating memory of cur having deleted data

return ele;/*returning the ele variable containing top element to the main function switch case2 for deletion operation*/

}

}

void display()

{

stk *cur;//declaring cur pointer variable as a temporary variable to hold top positioned data

if(top==NULL)

{

printf(\"stk is empty\ \");

return ;

}

else

{

cur=top;//sending top positioned data into cur pointer variable

while(cur!=NULL)/*untill the stack first position i.e cur variable which is pointing top position becomes NULL i.e empty loop runs*/

{

printf(\"%d\ \",cur->data);//prints the top positioned integer data

cur=cur->next;//cur variable holding next element data and again printing the element till cur=NULL

}

}

}

 Section 1: Project Objectives .Makes use of C-string library Read from and write to a text file Design and access structures Array of structures Learn to use p
 Section 1: Project Objectives .Makes use of C-string library Read from and write to a text file Design and access structures Array of structures Learn to use p
 Section 1: Project Objectives .Makes use of C-string library Read from and write to a text file Design and access structures Array of structures Learn to use p

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site