lec 1
and other things this is mad confusing
This commit is contained in:
commit
045d7367a8
11 files changed
+349
No files matched your search
+27
@@ -0,0 +1,27 @@
|
||||
# lab 2
|
||||
|
||||
## ex 1
|
||||
|
||||
Suppose that we use a List data structure to represent unbounded
|
||||
integers.
|
||||
|
||||
- the first element refers to the sign: 1 is positive and -1 is negative.
|
||||
- each element in the list represents one digit of these integers.
|
||||
|
||||
Implement and test the program in C/C++ using an Array-based List (Static or Dynamic) to manage this unbounded integers:
|
||||
|
||||
- add new digits at any place in an integer.
|
||||
- remove a digit at a specfic position in an integer.
|
||||
- calculate the sum of all digits from an unbounded integer.
|
||||
- display the whole number on the screen.
|
||||
|
||||
## ex 2
|
||||
|
||||
Assume that a railway train has N railroad cars attached together such as car1, car2, car3, ..., carN . A train can be considered as a list and each car corresponds to a node in this list.
|
||||
|
||||
- Each car carries a maximum capacity of passengers (int type) and has an id (char type). Both variables are user-defined values.
|
||||
- Each car is reserved by a number of passengers (int type) (which should be less than its capacity). If there are any cars that don’t have any passengers, they should be removed from the train.
|
||||
- It is possible to add new cars to the train.
|
||||
- A function is available to display all cars’ information or the length of the train.
|
||||
|
||||
Implement a program in C/C++ using Linked List to manage the train and test all functions.
|
||||
@@ -0,0 +1,22 @@
|
||||
#include "../common/arraylist.h"
|
||||
#include <stdio.h>
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
ldaArrayList lda;
|
||||
ldalistinit(&lda);
|
||||
ldalistpush(&lda, 1);
|
||||
ldalistpush(&lda, 2);
|
||||
ldalistpush(&lda, 5);
|
||||
ldalistpush(&lda, 10);
|
||||
ldalistpush(&lda, 20);
|
||||
ldalistpush(&lda, 30);
|
||||
ldalistadd(&lda, 4, 50); // correct af
|
||||
ldalistprint(&lda);
|
||||
int g;
|
||||
ldalistpop(&lda, &g);
|
||||
int f;
|
||||
ldalistremove(&lda, 6, &f);
|
||||
ldalistprint(&lda);
|
||||
printf("%d %d",g, f);
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user