Witam mam do napisania taki program który rozdziela łańcuch znaków gdy napotka zadany symbol np: "+" Zapisuje je do wskaźników utworzonych mallokiem tworzy z tych wskaźników listę dwu kierunkową i tworzy "interfejs" do przeglądania jej, to znaczy umożliwia wyświetlanie poszczególnych węzłów i przeskakiwanie pomiędzy nimi.
Mam utworzoną liste i "interfejs" do przegladania jednak dziala na integer, nie wiem jak zrobic zeby dzialalo na stringach.
#include<stdio.h>
#include<stdlib.h>
struct Node {
int data;
struct Node* next;
struct Node* prev;
};
struct Node* head;
struct Node* GetNewNode(int x) {
struct Node* newNode = malloc(sizeof(struct Node));
newNode->data = x;
newNode->prev = NULL;
newNode->next = NULL;
return newNode;
}
void Insert(int x) {
struct Node* newNode = GetNewNode(x);
if(head == NULL) {
head = newNode;
return;
}
head->prev = newNode;
newNode->next = head;
head = newNode;
}
void Print() {
struct Node* temp = head;
printf("Forward: ");
while(temp != NULL)
{
printf("%d ",temp->data);
temp = temp->next;
}
printf("\n");
}
void wypisz(){
struct Node* temp = head;
char z;
printf("%d\n", temp->data);
printf("Poruszasz sie W S, aby zakonczyc wcisnij n\n");
z = getchar();
getchar();
while (temp)
switch (z)
{
case 'w':
case 'W':
temp = temp->next;
printf("kolejnty to: %d \n", temp->data);
z = getchar();
getchar();
break;
case 's':
case 'S':
temp = temp->prev;
printf("poprzedni to: %d\n", temp->data);
z = getchar();
getchar();
break;
case 'N':
case 'n':
temp = NULL;
break;
default:
printf("Nieprawidlowy klawisz\n");
z = getchar();
getchar();
break;
}
}
int main()
{
head = NULL;
int n=5,i,a;
for(i=0;i<n;i++)
{
printf("Podaj 5 liczb do listy\n");
scanf("%d",&a);
Insert(a);
Print();
}
wypisz();
}