Skip to content

Commit 5bd8cad

Browse files
Fixed suggestion and loading not matching size of search bar. Disabled search button for now
1 parent 0c470d3 commit 5bd8cad

File tree

2 files changed

+117
-3
lines changed

2 files changed

+117
-3
lines changed

src/components/searchbar.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,16 @@ function SearchBar () {
8181
placeholder="Search..."
8282
className={`w-full rounded-xl border px-4 py-6 pr-10 bg-[#7480FF] placeholder:text-white text-white opacity-50 shadow-sm focus:outline-none focus:ring-2 ${loading ? 'opacity-70' : ''}`}
8383
/>
84-
<button type="submit" className="absolute inset-y-0 right-0 flex items-center pr-3" disabled={loading}>
84+
<button type="submit" className="absolute inset-y-0 right-0 flex items-center pr-3" disabled> {/* disabled={loading} */}
8585
<Search className="h-5 w-5 text-white opacity-50" />
8686
</button>
87-
</div>
8887
{loading && (
8988
<div className="absolute z-20 w-full max-w-xl border bg-white border-[#7480FF] dark:bg-[#030712] rounded-md mt-2 p-2 text-center">
9089
Loading suggestions...
9190
</div>
9291
)}
9392
{(suggestions.length > 0 || error) && !loading && (
94-
<ul ref={suggestionsRef} className="absolute mx-0.5 md:mx-0 md:w-full text-center max-w-xl z-20 border bg-white border-[#7480FF] dark:bg-[#030712] rounded-md mt-2">
93+
<ul ref={suggestionsRef} className="absolute mx-0.5 md:mx-0 w-full text-center max-w-xl z-20 border bg-white border-[#7480FF] dark:bg-[#030712] rounded-md mt-2">
9594
{error ? (
9695
<li className="p-2 text-red">{error}</li>
9796
) : (
@@ -108,6 +107,7 @@ function SearchBar () {
108107
)}
109108
</ul>
110109
)}
110+
</div>
111111
</form>
112112
</div>
113113
);

test.c

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
2+
// C program to add two polynomials
3+
#include <stdio.h>
4+
#include <stdlib.h>
5+
6+
struct Node
7+
{
8+
int coeff;
9+
int pow;
10+
struct Node *next;
11+
};
12+
13+
struct Node *createNode(int c, int p);
14+
15+
struct Node *addPolynomial(struct Node *head1, struct Node *head2)
16+
{
17+
struct Node *dummy = createNode(0, 0);
18+
19+
// Node to append other nodes to the end
20+
// of list
21+
struct Node *prev = dummy;
22+
struct Node *curr1 = head1, *curr2 = head2;
23+
24+
while (curr1 != NULL && curr2 != NULL)
25+
{
26+
// if curr2.pow > curr1.pow, then
27+
// append curr2 to list
28+
29+
if (curr1->pow < curr2->pow)
30+
{
31+
prev->next = curr2; // dummy next = curr2
32+
prev = curr2; // now make prev as curr2, so after this next for curr2 changes.
33+
curr2 = curr2->next; // now curr 2 is next value
34+
}
35+
// if curr1.pow > curr2.pow, then
36+
// append curr2 to list
37+
else if (curr1->pow > curr2->pow)
38+
{
39+
prev->next = curr1;
40+
prev = curr1;
41+
curr1 = curr1->next;
42+
}
43+
44+
// else, add the sum of curr1->coeff and
45+
// curr2->coeff to curr1->coeff, and append
46+
// curr1 to the list
47+
else
48+
{
49+
curr1->coeff = curr1->coeff + curr2->coeff;
50+
prev->next = curr1;
51+
prev = curr1;
52+
curr1 = curr1->next;
53+
curr2 = curr2->next;
54+
}
55+
}
56+
57+
// if curr1 is not null, then append the rest
58+
// to the list
59+
if (curr1 != NULL)
60+
{
61+
prev->next = curr1;
62+
}
63+
64+
// if curr2 is not null, then append the rest
65+
// to the list
66+
if (curr2 != NULL)
67+
{
68+
prev->next = curr2;
69+
}
70+
71+
return dummy->next;
72+
}
73+
74+
void printList(struct Node *head)
75+
{
76+
struct Node *curr = head;
77+
78+
while (curr != NULL)
79+
{
80+
printf("%d,%d ", curr->coeff, curr->pow);
81+
curr = curr->next;
82+
}
83+
84+
printf("\n");
85+
}
86+
87+
struct Node *createNode(int c, int p)
88+
{
89+
struct Node *newNode =
90+
(struct Node *)malloc(sizeof(struct Node));
91+
newNode->coeff = c;
92+
newNode->pow = p;
93+
newNode->next = NULL;
94+
return newNode;
95+
}
96+
97+
int main()
98+
{
99+
100+
// 1st polynomial: 5x^2+4x^1+2x^0
101+
struct Node *head1 = createNode(5, 2);
102+
head1->next = createNode(4, 1);
103+
head1->next->next = createNode(2, 0);
104+
105+
// 2nd polynomial: -5x^1-5x^0
106+
struct Node *head2 = createNode(-5, 1);
107+
head2->next = createNode(-5, 0);
108+
109+
struct Node *head = addPolynomial(head1, head2);
110+
111+
printList(head);
112+
113+
return 0;
114+
}

0 commit comments

Comments
 (0)